Micron Document
<!DOCTYPE html>
<html class="client-nojs vector-feature-night-mode-disabled vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-sticky-header-enabled" lang="en" dir="ltr"><head>
<meta charset="UTF-8">
<title>Dynamic programming</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="https://en.wikipedia.org/wiki/Dynamic_programming"> <link href="./mw/ext.cite.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/ext.math.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/ext.pygments.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.icons.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.search.codex.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/user.styles.css" rel="stylesheet" type="text/css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" type="text/css" href="./mw/site.styles.css">
<link rel="stylesheet" type="text/css" href="./mw/noscript.css">
<link rel="stylesheet" type="text/css" href="./footer.css">
<link rel="stylesheet" type="text/css" href="./vector-2022.css">
</head>
<body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject page-Dynamic_programming rootpage-Dynamic_programming skin-vector-2022 action-view">
<div class="mw-page-container">
<div class="mw-page-container-inner">
<div class="mw-content-container">
<main id="content" class="mw-body">
<header class="mw-body-header vector-page-titlebar">
<h1 id="firstHeading" class="firstHeading mw-first-heading">
<span id="openzim-page-title" class="mw-page-title-main"><span class="mw-page-title-main">Dynamic programming</span></span>
</h1>
</header>
<a id="top"></a>
<div id="bodyContent" class="vector-body ve-init-mw-desktopArticleTarget-targetContainer" aria-labelledby="firstHeading" data-mw-ve-target-container="">
<div id="mw-content-text" class="mw-body-content mw-content-ltr" lang="en" dir="ltr"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr">
<style data-mw-deduplicate="TemplateStyles:r1236090951">
/* start https://en.wikipedia.org/ */


.mw-parser-output .hatnote{font-style:italic}.mw-parser-output div.hatnote{padding-left:1.6em;margin-bottom:0.5em}.mw-parser-output .hatnote i{font-style:normal}.mw-parser-output .hatnote+link+.hatnote{margin-top:-0.5em}@media print{body.ns-0 .mw-parser-output .hatnote{display:none!important}}


/* end https://en.wikipedia.org/ */
</style><div role="note" class="hatnote navigation-not-searchable">Not to be confused with <a href="Dynamic_programming_language" title="Dynamic programming language">Dynamic programming language</a> or <a href="Dynamic_problem" class="mw-redirect" title="Dynamic problem">Dynamic problem</a>.</div>

<p><b>Dynamic programming</b> is both a <a href="Mathematical_optimization" title="Mathematical optimization">mathematical optimization</a> method and an <a href="Algorithmic_paradigm" title="Algorithmic paradigm">algorithmic paradigm</a>. The method was developed by <a href="Richard_Bellman" class="mw-redirect" title="Richard Bellman">Richard Bellman</a> in the 1950s and has found applications in numerous fields, from <a href="Aerospace_engineering" title="Aerospace engineering">aerospace engineering</a> to <a href="Economics" title="Economics">economics</a>.
</p><p>In both contexts it refers to simplifying a complicated problem by breaking it down into simpler sub-problems in a <a href="Recursion" title="Recursion">recursive</a> manner. While some decision problems cannot be taken apart this way, decisions that span several points in time do often break apart recursively. Likewise, in computer science, if a problem can be solved optimally by breaking it into sub-problems and then recursively finding the optimal solutions to the sub-problems, then it is said to have <i><a href="Optimal_substructure" title="Optimal substructure">optimal substructure</a></i>.
</p><p>If sub-problems can be nested recursively inside larger problems, so that dynamic programming methods are applicable, then there is a relation between the value of the larger problem and the values of the sub-problems.<sup id="cite_ref-:0_1-0" class="reference"><a href="#cite_note-:0-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup> In the optimization literature this relationship is called the <a href="Bellman_equation" title="Bellman equation">Bellman equation</a>.
</p>
<meta property="mw:PageProp/toc">
<div class="mw-heading mw-heading2"><h2 id="Overview">Overview</h2></div>
<div class="mw-heading mw-heading3"><h3 id="Mathematical_optimization">Mathematical optimization</h3></div>
<p>In terms of mathematical optimization, dynamic programming usually refers to simplifying a decision by breaking it down into a sequence of decision steps over time.
</p><p>This is done by defining a sequence of <b>value functions</b> <i>V</i><sub>1</sub>, <i>V</i><sub>2</sub>, ..., <i>V</i><sub><i>n</i></sub> taking <i>y</i> as an argument representing the <b><a href="State_variable" title="State variable">state</a></b> of the system at times <i>i</i> from 1 to <i>n</i>.
</p><p>The definition of <i>V</i><sub><i>n</i></sub>(<i>y</i>) is the value obtained in state <i>y</i> at the last time <i>n</i>.
</p><p>The values <i>V</i><sub><i>i</i></sub> at earlier times <i>i</i>&nbsp;=&nbsp;<i>n</i>&nbsp;−1,&nbsp;<i>n</i>&nbsp;−&nbsp;2,&nbsp;...,&nbsp;2,&nbsp;1 can be found by working backwards, using a <a href="Recursion" title="Recursion">recursive</a> relationship called the <a href="Bellman_equation" title="Bellman equation">Bellman equation</a>.
</p><p>For <i>i</i>&nbsp;=&nbsp;2,&nbsp;...,&nbsp;<i>n</i>, <i>V</i><sub><i>i</i>−1</sub> at any state <i>y</i> is calculated from <i>V</i><sub><i>i</i></sub> by maximizing a simple function (usually the sum) of the gain from a decision at time <i>i</i>&nbsp;−&nbsp;1 and the function <i>V</i><sub><i>i</i></sub> at the new state of the system if this decision is made.
</p><p>Since <i>V</i><sub><i>i</i></sub> has already been calculated for the needed states, the above operation yields <i>V</i><sub><i>i</i>−1</sub> for those states.
</p><p>Finally, <i>V</i><sub>1</sub> at the initial state of the system is the value of the optimal solution. The optimal values of the decision variables can be recovered, one by one, by tracking back the calculations already performed.
</p>
<div class="mw-heading mw-heading3"><h3 id="Control_theory">Control theory</h3></div>
<p>In <a href="Control_theory" title="Control theory">control theory</a>, a typical problem is to find an admissible control <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \mathbf {u} ^{\ast }}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msup>
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="bold">u</mi>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mo>∗<!-- ∗ --></mo>
</mrow>
</msup>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \mathbf {u} ^{\ast }}</annotation>
</semantics>
</math></span><img src="./28af30b0ccc5031ab9197b5513a023d619223c38.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:2.54ex; height:2.343ex;" alt="{\displaystyle \mathbf {u} ^{\ast }}" loading="lazy"></span> which causes the system <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle {\dot {\mathbf {x} }}(t)=\mathbf {g} \left(\mathbf {x} (t),\mathbf {u} (t),t\right)}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mrow class="MJX-TeXAtom-ORD">
<mrow class="MJX-TeXAtom-ORD">
<mover>
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="bold">x</mi>
</mrow>
<mo>˙<!-- ˙ --></mo>
</mover>
</mrow>
</mrow>
<mo stretchy="false">(</mo>
<mi>t</mi>
<mo stretchy="false">)</mo>
<mo>=</mo>
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="bold">g</mi>
</mrow>
<mrow>
<mo>(</mo>
<mrow>
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="bold">x</mi>
</mrow>
<mo stretchy="false">(</mo>
<mi>t</mi>
<mo stretchy="false">)</mo>
<mo>,</mo>
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="bold">u</mi>
</mrow>
<mo stretchy="false">(</mo>
<mi>t</mi>
<mo stretchy="false">)</mo>
<mo>,</mo>
<mi>t</mi>
</mrow>
<mo>)</mo>
</mrow>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle {\dot {\mathbf {x} }}(t)=\mathbf {g} \left(\mathbf {x} (t),\mathbf {u} (t),t\right)}</annotation>
</semantics>
</math></span><img src="./6f8ac19503069e99fd6509049eb8184ab4456fd8.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:21.793ex; height:2.843ex;" alt="{\displaystyle {\dot {\mathbf {x} }}(t)=\mathbf {g} \left(\mathbf {x} (t),\mathbf {u} (t),t\right)}" loading="lazy"></span> to follow an admissible trajectory <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \mathbf {x} ^{\ast }}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msup>
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="bold">x</mi>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mo>∗<!-- ∗ --></mo>
</mrow>
</msup>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \mathbf {x} ^{\ast }}</annotation>
</semantics>
</math></span><img src="./b7a902678bff3be2ae29f828d78594ce61eb5031.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:2.465ex; height:2.343ex;" alt="{\displaystyle \mathbf {x} ^{\ast }}" loading="lazy"></span> on a continuous time interval <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle t_{0}\leq t\leq t_{1}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>t</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>0</mn>
</mrow>
</msub>
<mo>≤<!-- ≤ --></mo>
<mi>t</mi>
<mo>≤<!-- ≤ --></mo>
<msub>
<mi>t</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>1</mn>
</mrow>
</msub>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle t_{0}\leq t\leq t_{1}}</annotation>
</semantics>
</math></span><img src="./a409858d7eb32c359f8ea1f6d5cd3efa96d22ae1.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:10.824ex; height:2.343ex;" alt="{\displaystyle t_{0}\leq t\leq t_{1}}" loading="lazy"></span> that minimizes a <a href="Loss_function" title="Loss function">cost function</a>
</p>
<dl><dd><span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle J=b\left(\mathbf {x} (t_{1}),t_{1}\right)+\int _{t_{0}}^{t_{1}}f\left(\mathbf {x} (t),\mathbf {u} (t),t\right)\mathrm {d} t}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>J</mi>
<mo>=</mo>
<mi>b</mi>
<mrow>
<mo>(</mo>
<mrow>
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="bold">x</mi>
</mrow>
<mo stretchy="false">(</mo>
<msub>
<mi>t</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>1</mn>
</mrow>
</msub>
<mo stretchy="false">)</mo>
<mo>,</mo>
<msub>
<mi>t</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>1</mn>
</mrow>
</msub>
</mrow>
<mo>)</mo>
</mrow>
<mo>+</mo>
<msubsup>
<mo>∫<!-- ∫ --></mo>
<mrow class="MJX-TeXAtom-ORD">
<msub>
<mi>t</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>0</mn>
</mrow>
</msub>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<msub>
<mi>t</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>1</mn>
</mrow>
</msub>
</mrow>
</msubsup>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mrow>
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="bold">x</mi>
</mrow>
<mo stretchy="false">(</mo>
<mi>t</mi>
<mo stretchy="false">)</mo>
<mo>,</mo>
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="bold">u</mi>
</mrow>
<mo stretchy="false">(</mo>
<mi>t</mi>
<mo stretchy="false">)</mo>
<mo>,</mo>
<mi>t</mi>
</mrow>
<mo>)</mo>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="normal">d</mi>
</mrow>
<mi>t</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle J=b\left(\mathbf {x} (t_{1}),t_{1}\right)+\int _{t_{0}}^{t_{1}}f\left(\mathbf {x} (t),\mathbf {u} (t),t\right)\mathrm {d} t}</annotation>
</semantics>
</math></span><img src="./63bfe1f0100954ebfb540d6e01d7cc097a317491.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -2.671ex; width:40.251ex; height:6.509ex;" alt="{\displaystyle J=b\left(\mathbf {x} (t_{1}),t_{1}\right)+\int _{t_{0}}^{t_{1}}f\left(\mathbf {x} (t),\mathbf {u} (t),t\right)\mathrm {d} t}" loading="lazy"></span></dd></dl>
<p>The solution to this problem is an optimal control law or policy <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \mathbf {u} ^{\ast }=h(\mathbf {x} (t),t)}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msup>
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="bold">u</mi>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mo>∗<!-- ∗ --></mo>
</mrow>
</msup>
<mo>=</mo>
<mi>h</mi>
<mo stretchy="false">(</mo>
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="bold">x</mi>
</mrow>
<mo stretchy="false">(</mo>
<mi>t</mi>
<mo stretchy="false">)</mo>
<mo>,</mo>
<mi>t</mi>
<mo stretchy="false">)</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \mathbf {u} ^{\ast }=h(\mathbf {x} (t),t)}</annotation>
</semantics>
</math></span><img src="./7422ca3ab6f0137a3c2075c97f33b2f046dd7cd6.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:14.72ex; height:2.843ex;" alt="{\displaystyle \mathbf {u} ^{\ast }=h(\mathbf {x} (t),t)}" loading="lazy"></span>, which produces an optimal trajectory <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \mathbf {x} ^{\ast }}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msup>
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="bold">x</mi>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mo>∗<!-- ∗ --></mo>
</mrow>
</msup>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \mathbf {x} ^{\ast }}</annotation>
</semantics>
</math></span><img src="./b7a902678bff3be2ae29f828d78594ce61eb5031.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:2.465ex; height:2.343ex;" alt="{\displaystyle \mathbf {x} ^{\ast }}" loading="lazy"></span> and a <a href="Cost-to-go_function" class="mw-redirect" title="Cost-to-go function">cost-to-go function</a> <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle J^{\ast }}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msup>
<mi>J</mi>
<mrow class="MJX-TeXAtom-ORD">
<mo>∗<!-- ∗ --></mo>
</mrow>
</msup>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle J^{\ast }}</annotation>
</semantics>
</math></span><img src="./6e1c3cf6b0f82086b63804e6ff6db19a003516f4.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:2.58ex; height:2.343ex;" alt="{\displaystyle J^{\ast }}" loading="lazy"></span>. The latter obeys the fundamental equation of dynamic programming:
</p>
<dl><dd><span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle -J_{t}^{\ast }=\min _{\mathbf {u} }\left\{f\left(\mathbf {x} (t),\mathbf {u} (t),t\right)+J_{x}^{\ast {\mathsf {T}}}\mathbf {g} \left(\mathbf {x} (t),\mathbf {u} (t),t\right)\right\}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mo>−<!-- − --></mo>
<msubsup>
<mi>J</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>t</mi>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mo>∗<!-- ∗ --></mo>
</mrow>
</msubsup>
<mo>=</mo>
<munder>
<mo movablelimits="true" form="prefix">min</mo>
<mrow class="MJX-TeXAtom-ORD">
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="bold">u</mi>
</mrow>
</mrow>
</munder>
<mrow>
<mo>{</mo>
<mrow>
<mi>f</mi>
<mrow>
<mo>(</mo>
<mrow>
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="bold">x</mi>
</mrow>
<mo stretchy="false">(</mo>
<mi>t</mi>
<mo stretchy="false">)</mo>
<mo>,</mo>
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="bold">u</mi>
</mrow>
<mo stretchy="false">(</mo>
<mi>t</mi>
<mo stretchy="false">)</mo>
<mo>,</mo>
<mi>t</mi>
</mrow>
<mo>)</mo>
</mrow>
<mo>+</mo>
<msubsup>
<mi>J</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>x</mi>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mo>∗<!-- ∗ --></mo>
<mrow class="MJX-TeXAtom-ORD">
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="sans-serif">T</mi>
</mrow>
</mrow>
</mrow>
</msubsup>
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="bold">g</mi>
</mrow>
<mrow>
<mo>(</mo>
<mrow>
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="bold">x</mi>
</mrow>
<mo stretchy="false">(</mo>
<mi>t</mi>
<mo stretchy="false">)</mo>
<mo>,</mo>
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="bold">u</mi>
</mrow>
<mo stretchy="false">(</mo>
<mi>t</mi>
<mo stretchy="false">)</mo>
<mo>,</mo>
<mi>t</mi>
</mrow>
<mo>)</mo>
</mrow>
</mrow>
<mo>}</mo>
</mrow>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle -J_{t}^{\ast }=\min _{\mathbf {u} }\left\{f\left(\mathbf {x} (t),\mathbf {u} (t),t\right)+J_{x}^{\ast {\mathsf {T}}}\mathbf {g} \left(\mathbf {x} (t),\mathbf {u} (t),t\right)\right\}}</annotation>
</semantics>
</math></span><img src="./61adf643857b96a01a978deeae8355d98c6c2777.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -1.838ex; width:50.21ex; height:4.009ex;" alt="{\displaystyle -J_{t}^{\ast }=\min _{\mathbf {u} }\left\{f\left(\mathbf {x} (t),\mathbf {u} (t),t\right)+J_{x}^{\ast {\mathsf {T}}}\mathbf {g} \left(\mathbf {x} (t),\mathbf {u} (t),t\right)\right\}}" loading="lazy"></span></dd></dl>
<p>a <a href="Partial_differential_equation" title="Partial differential equation">partial differential equation</a> known as the <a href="Hamilton%E2%80%93Jacobi%E2%80%93Bellman_equation" title="Hamilton–Jacobi–Bellman equation">Hamilton–Jacobi–Bellman equation</a>, in which <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle J_{x}^{\ast }={\frac {\partial J^{\ast }}{\partial \mathbf {x} }}=\left[{\frac {\partial J^{\ast }}{\partial x_{1}}}~~~~{\frac {\partial J^{\ast }}{\partial x_{2}}}~~~~\dots ~~~~{\frac {\partial J^{\ast }}{\partial x_{n}}}\right]^{\mathsf {T}}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msubsup>
<mi>J</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>x</mi>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mo>∗<!-- ∗ --></mo>
</mrow>
</msubsup>
<mo>=</mo>
<mrow class="MJX-TeXAtom-ORD">
<mfrac>
<mrow>
<mi mathvariant="normal">∂<!-- ∂ --></mi>
<msup>
<mi>J</mi>
<mrow class="MJX-TeXAtom-ORD">
<mo>∗<!-- ∗ --></mo>
</mrow>
</msup>
</mrow>
<mrow>
<mi mathvariant="normal">∂<!-- ∂ --></mi>
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="bold">x</mi>
</mrow>
</mrow>
</mfrac>
</mrow>
<mo>=</mo>
<msup>
<mrow>
<mo>[</mo>
<mrow>
<mrow class="MJX-TeXAtom-ORD">
<mfrac>
<mrow>
<mi mathvariant="normal">∂<!-- ∂ --></mi>
<msup>
<mi>J</mi>
<mrow class="MJX-TeXAtom-ORD">
<mo>∗<!-- ∗ --></mo>
</mrow>
</msup>
</mrow>
<mrow>
<mi mathvariant="normal">∂<!-- ∂ --></mi>
<msub>
<mi>x</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>1</mn>
</mrow>
</msub>
</mrow>
</mfrac>
</mrow>
<mtext>&nbsp;</mtext>
<mtext>&nbsp;</mtext>
<mtext>&nbsp;</mtext>
<mtext>&nbsp;</mtext>
<mrow class="MJX-TeXAtom-ORD">
<mfrac>
<mrow>
<mi mathvariant="normal">∂<!-- ∂ --></mi>
<msup>
<mi>J</mi>
<mrow class="MJX-TeXAtom-ORD">
<mo>∗<!-- ∗ --></mo>
</mrow>
</msup>
</mrow>
<mrow>
<mi mathvariant="normal">∂<!-- ∂ --></mi>
<msub>
<mi>x</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msub>
</mrow>
</mfrac>
</mrow>
<mtext>&nbsp;</mtext>
<mtext>&nbsp;</mtext>
<mtext>&nbsp;</mtext>
<mtext>&nbsp;</mtext>
<mo>…<!-- … --></mo>
<mtext>&nbsp;</mtext>
<mtext>&nbsp;</mtext>
<mtext>&nbsp;</mtext>
<mtext>&nbsp;</mtext>
<mrow class="MJX-TeXAtom-ORD">
<mfrac>
<mrow>
<mi mathvariant="normal">∂<!-- ∂ --></mi>
<msup>
<mi>J</mi>
<mrow class="MJX-TeXAtom-ORD">
<mo>∗<!-- ∗ --></mo>
</mrow>
</msup>
</mrow>
<mrow>
<mi mathvariant="normal">∂<!-- ∂ --></mi>
<msub>
<mi>x</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>n</mi>
</mrow>
</msub>
</mrow>
</mfrac>
</mrow>
</mrow>
<mo>]</mo>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="sans-serif">T</mi>
</mrow>
</mrow>
</msup>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle J_{x}^{\ast }={\frac {\partial J^{\ast }}{\partial \mathbf {x} }}=\left[{\frac {\partial J^{\ast }}{\partial x_{1}}}~~~~{\frac {\partial J^{\ast }}{\partial x_{2}}}~~~~\dots ~~~~{\frac {\partial J^{\ast }}{\partial x_{n}}}\right]^{\mathsf {T}}}</annotation>
</semantics>
</math></span><img src="./2d8ec705f00169c8ea3c0daa2d2669fdc623f403.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -2.505ex; width:41.986ex; height:6.676ex;" alt="{\displaystyle J_{x}^{\ast }={\frac {\partial J^{\ast }}{\partial \mathbf {x} }}=\left[{\frac {\partial J^{\ast }}{\partial x_{1}}}~~~~{\frac {\partial J^{\ast }}{\partial x_{2}}}~~~~\dots ~~~~{\frac {\partial J^{\ast }}{\partial x_{n}}}\right]^{\mathsf {T}}}" loading="lazy"></span> and <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle J_{t}^{\ast }={\frac {\partial J^{\ast }}{\partial t}}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msubsup>
<mi>J</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>t</mi>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mo>∗<!-- ∗ --></mo>
</mrow>
</msubsup>
<mo>=</mo>
<mrow class="MJX-TeXAtom-ORD">
<mfrac>
<mrow>
<mi mathvariant="normal">∂<!-- ∂ --></mi>
<msup>
<mi>J</mi>
<mrow class="MJX-TeXAtom-ORD">
<mo>∗<!-- ∗ --></mo>
</mrow>
</msup>
</mrow>
<mrow>
<mi mathvariant="normal">∂<!-- ∂ --></mi>
<mi>t</mi>
</mrow>
</mfrac>
</mrow>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle J_{t}^{\ast }={\frac {\partial J^{\ast }}{\partial t}}}</annotation>
</semantics>
</math></span><img src="./5e86a16697bf1460ff23621e25902160f9d5d6b6.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -2.005ex; width:10.413ex; height:5.509ex;" alt="{\displaystyle J_{t}^{\ast }={\frac {\partial J^{\ast }}{\partial t}}}" loading="lazy"></span>. One finds that minimizing <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \mathbf {u} }">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="bold">u</mi>
</mrow>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \mathbf {u} }</annotation>
</semantics>
</math></span><img src="./261e20fe101de02a771021d9d4466c0ad3e352d7.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.485ex; height:1.676ex;" alt="{\displaystyle \mathbf {u} }" loading="lazy"></span> in terms of <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle t}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>t</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle t}</annotation>
</semantics>
</math></span><img src="./65658b7b223af9e1acc877d848888ecdb4466560.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:0.84ex; height:2.009ex;" alt="{\displaystyle t}" loading="lazy"></span>, <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \mathbf {x} }">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="bold">x</mi>
</mrow>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \mathbf {x} }</annotation>
</semantics>
</math></span><img src="./32adf004df5eb0a8c7fd8c0b6b7405183c5a5ef2.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.411ex; height:1.676ex;" alt="{\displaystyle \mathbf {x} }" loading="lazy"></span>, and the unknown function <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle J_{x}^{\ast }}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msubsup>
<mi>J</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>x</mi>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mo>∗<!-- ∗ --></mo>
</mrow>
</msubsup>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle J_{x}^{\ast }}</annotation>
</semantics>
</math></span><img src="./3c55442c83748a8d936380bdd4caafdbe04059aa.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:2.58ex; height:2.509ex;" alt="{\displaystyle J_{x}^{\ast }}" loading="lazy"></span> and then substitutes the result into the Hamilton–Jacobi–Bellman equation to get the partial differential equation to be solved with boundary condition <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle J\left(t_{1}\right)=b\left(\mathbf {x} (t_{1}),t_{1}\right)}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>J</mi>
<mrow>
<mo>(</mo>
<msub>
<mi>t</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>1</mn>
</mrow>
</msub>
<mo>)</mo>
</mrow>
<mo>=</mo>
<mi>b</mi>
<mrow>
<mo>(</mo>
<mrow>
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="bold">x</mi>
</mrow>
<mo stretchy="false">(</mo>
<msub>
<mi>t</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>1</mn>
</mrow>
</msub>
<mo stretchy="false">)</mo>
<mo>,</mo>
<msub>
<mi>t</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>1</mn>
</mrow>
</msub>
</mrow>
<mo>)</mo>
</mrow>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle J\left(t_{1}\right)=b\left(\mathbf {x} (t_{1}),t_{1}\right)}</annotation>
</semantics>
</math></span><img src="./547d2411ff0ff93c17921a01645e765ed85832ca.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:19.896ex; height:2.843ex;" alt="{\displaystyle J\left(t_{1}\right)=b\left(\mathbf {x} (t_{1}),t_{1}\right)}" loading="lazy"></span>.<sup id="cite_ref-2" class="reference"><a href="#cite_note-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup> In practice, this generally requires <a href="Numerical_partial_differential_equations" class="mw-redirect" title="Numerical partial differential equations">numerical techniques</a> for some discrete approximation to the exact optimization relationship.
</p><p>Alternatively, the continuous process can be approximated by a discrete system, which leads to a following recurrence relation analog to the Hamilton–Jacobi–Bellman equation:
</p>
<dl><dd><span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle J_{k}^{\ast }\left(\mathbf {x} _{n-k}\right)=\min _{\mathbf {u} _{n-k}}\left\{{\hat {f}}\left(\mathbf {x} _{n-k},\mathbf {u} _{n-k}\right)+J_{k-1}^{\ast }\left({\hat {\mathbf {g} }}\left(\mathbf {x} _{n-k},\mathbf {u} _{n-k}\right)\right)\right\}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msubsup>
<mi>J</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>k</mi>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mo>∗<!-- ∗ --></mo>
</mrow>
</msubsup>
<mrow>
<mo>(</mo>
<msub>
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="bold">x</mi>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mi>n</mi>
<mo>−<!-- − --></mo>
<mi>k</mi>
</mrow>
</msub>
<mo>)</mo>
</mrow>
<mo>=</mo>
<munder>
<mo movablelimits="true" form="prefix">min</mo>
<mrow class="MJX-TeXAtom-ORD">
<msub>
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="bold">u</mi>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mi>n</mi>
<mo>−<!-- − --></mo>
<mi>k</mi>
</mrow>
</msub>
</mrow>
</munder>
<mrow>
<mo>{</mo>
<mrow>
<mrow class="MJX-TeXAtom-ORD">
<mrow class="MJX-TeXAtom-ORD">
<mover>
<mi>f</mi>
<mo stretchy="false">^<!-- ^ --></mo>
</mover>
</mrow>
</mrow>
<mrow>
<mo>(</mo>
<mrow>
<msub>
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="bold">x</mi>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mi>n</mi>
<mo>−<!-- − --></mo>
<mi>k</mi>
</mrow>
</msub>
<mo>,</mo>
<msub>
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="bold">u</mi>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mi>n</mi>
<mo>−<!-- − --></mo>
<mi>k</mi>
</mrow>
</msub>
</mrow>
<mo>)</mo>
</mrow>
<mo>+</mo>
<msubsup>
<mi>J</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>k</mi>
<mo>−<!-- − --></mo>
<mn>1</mn>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mo>∗<!-- ∗ --></mo>
</mrow>
</msubsup>
<mrow>
<mo>(</mo>
<mrow>
<mrow class="MJX-TeXAtom-ORD">
<mrow class="MJX-TeXAtom-ORD">
<mover>
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="bold">g</mi>
</mrow>
<mo stretchy="false">^<!-- ^ --></mo>
</mover>
</mrow>
</mrow>
<mrow>
<mo>(</mo>
<mrow>
<msub>
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="bold">x</mi>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mi>n</mi>
<mo>−<!-- − --></mo>
<mi>k</mi>
</mrow>
</msub>
<mo>,</mo>
<msub>
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="bold">u</mi>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mi>n</mi>
<mo>−<!-- − --></mo>
<mi>k</mi>
</mrow>
</msub>
</mrow>
<mo>)</mo>
</mrow>
</mrow>
<mo>)</mo>
</mrow>
</mrow>
<mo>}</mo>
</mrow>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle J_{k}^{\ast }\left(\mathbf {x} _{n-k}\right)=\min _{\mathbf {u} _{n-k}}\left\{{\hat {f}}\left(\mathbf {x} _{n-k},\mathbf {u} _{n-k}\right)+J_{k-1}^{\ast }\left({\hat {\mathbf {g} }}\left(\mathbf {x} _{n-k},\mathbf {u} _{n-k}\right)\right)\right\}}</annotation>
</semantics>
</math></span><img src="./194904c21e87d196178765721674bf7708922650.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -2.338ex; width:58.221ex; height:5.343ex;" alt="{\displaystyle J_{k}^{\ast }\left(\mathbf {x} _{n-k}\right)=\min _{\mathbf {u} _{n-k}}\left\{{\hat {f}}\left(\mathbf {x} _{n-k},\mathbf {u} _{n-k}\right)+J_{k-1}^{\ast }\left({\hat {\mathbf {g} }}\left(\mathbf {x} _{n-k},\mathbf {u} _{n-k}\right)\right)\right\}}" loading="lazy"></span></dd></dl>
<p>at the <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle k}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>k</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle k}</annotation>
</semantics>
</math></span><img src="./c3c9a2c7b599b37105512c5d570edc034056dd40.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.211ex; height:2.176ex;" alt="{\displaystyle k}" loading="lazy"></span>-th stage of <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle n}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>n</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle n}</annotation>
</semantics>
</math></span><img src="./a601995d55609f2d9f5e233e36fbe9ea26011b3b.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.395ex; height:1.676ex;" alt="{\displaystyle n}" loading="lazy"></span> equally spaced discrete time intervals, and where <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle {\hat {f}}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mrow class="MJX-TeXAtom-ORD">
<mrow class="MJX-TeXAtom-ORD">
<mover>
<mi>f</mi>
<mo stretchy="false">^<!-- ^ --></mo>
</mover>
</mrow>
</mrow>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle {\hat {f}}}</annotation>
</semantics>
</math></span><img src="./14ce989fd75da938ec6f95a0cdb71037b23a11cb.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:1.699ex; height:3.176ex;" alt="{\displaystyle {\hat {f}}}" loading="lazy"></span> and <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle {\hat {\mathbf {g} }}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mrow class="MJX-TeXAtom-ORD">
<mrow class="MJX-TeXAtom-ORD">
<mover>
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="bold">g</mi>
</mrow>
<mo stretchy="false">^<!-- ^ --></mo>
</mover>
</mrow>
</mrow>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle {\hat {\mathbf {g} }}}</annotation>
</semantics>
</math></span><img src="./24908acaef278644c6412d9c32d9feba222679c4.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:1.337ex; height:2.676ex;" alt="{\displaystyle {\hat {\mathbf {g} }}}" loading="lazy"></span> denote discrete approximations to <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle f}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>f</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle f}</annotation>
</semantics>
</math></span><img src="./132e57acb643253e7810ee9702d9581f159a1c61.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:1.279ex; height:2.509ex;" alt="{\displaystyle f}" loading="lazy"></span> and <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \mathbf {g} }">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="bold">g</mi>
</mrow>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \mathbf {g} }</annotation>
</semantics>
</math></span><img src="./8cdf843789e9564a867aee3ff184453b72ecbafe.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:1.337ex; height:2.009ex;" alt="{\displaystyle \mathbf {g} }" loading="lazy"></span>. This functional equation is known as the <a href="Bellman_equation" title="Bellman equation">Bellman equation</a>, which can be solved for an exact solution of the discrete approximation of the optimization equation.<sup id="cite_ref-3" class="reference"><a href="#cite_note-3"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading4"><h4 id="Example_from_economics:_Ramsey's_problem_of_optimal_saving">Example from economics: Ramsey's problem of optimal saving</h4></div>
<div role="note" class="hatnote navigation-not-searchable">See also: <a href="Ramsey%E2%80%93Cass%E2%80%93Koopmans_model" title="Ramsey–Cass–Koopmans model">Ramsey–Cass–Koopmans model</a></div>
<p>In <a href="Economics" title="Economics">economics</a>, the objective is generally to maximize (rather than minimize) some dynamic <a href="Social_welfare_function" title="Social welfare function">social welfare function</a>. In Ramsey's problem, this function relates amounts of consumption to levels of <a href="Utility" title="Utility">utility</a>. Loosely speaking, the planner faces the trade-off between contemporaneous consumption and future consumption (via investment in <a href="Physical_capital" title="Physical capital">capital stock</a> that is used in production), known as <a href="Intertemporal_choice" title="Intertemporal choice">intertemporal choice</a>. Future consumption is discounted at a constant rate <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \beta \in (0,1)}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>β<!-- β --></mi>
<mo>∈<!-- ∈ --></mo>
<mo stretchy="false">(</mo>
<mn>0</mn>
<mo>,</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \beta \in (0,1)}</annotation>
</semantics>
</math></span><img src="./78d19da4972d52ca3f15bcc2c141b09de4406d02.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:9.341ex; height:2.843ex;" alt="{\displaystyle \beta \in (0,1)}" loading="lazy"></span>. A discrete approximation to the transition equation of capital is given by
</p>
<dl><dd><span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle k_{t+1}={\hat {g}}\left(k_{t},c_{t}\right)=f(k_{t})-c_{t}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>k</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>t</mi>
<mo>+</mo>
<mn>1</mn>
</mrow>
</msub>
<mo>=</mo>
<mrow class="MJX-TeXAtom-ORD">
<mrow class="MJX-TeXAtom-ORD">
<mover>
<mi>g</mi>
<mo stretchy="false">^<!-- ^ --></mo>
</mover>
</mrow>
</mrow>
<mrow>
<mo>(</mo>
<mrow>
<msub>
<mi>k</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>t</mi>
</mrow>
</msub>
<mo>,</mo>
<msub>
<mi>c</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>t</mi>
</mrow>
</msub>
</mrow>
<mo>)</mo>
</mrow>
<mo>=</mo>
<mi>f</mi>
<mo stretchy="false">(</mo>
<msub>
<mi>k</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>t</mi>
</mrow>
</msub>
<mo stretchy="false">)</mo>
<mo>−<!-- − --></mo>
<msub>
<mi>c</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>t</mi>
</mrow>
</msub>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle k_{t+1}={\hat {g}}\left(k_{t},c_{t}\right)=f(k_{t})-c_{t}}</annotation>
</semantics>
</math></span><img src="./f8d32fbc9cb6f38e69731c90461d262f1d0f8134.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:28.465ex; height:2.843ex;" alt="{\displaystyle k_{t+1}={\hat {g}}\left(k_{t},c_{t}\right)=f(k_{t})-c_{t}}" loading="lazy"></span></dd></dl>
<p>where <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle c}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>c</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle c}</annotation>
</semantics>
</math></span><img src="./86a67b81c2de995bd608d5b2df50cd8cd7d92455.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.007ex; height:1.676ex;" alt="{\displaystyle c}" loading="lazy"></span> is consumption, <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle k}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>k</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle k}</annotation>
</semantics>
</math></span><img src="./c3c9a2c7b599b37105512c5d570edc034056dd40.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.211ex; height:2.176ex;" alt="{\displaystyle k}" loading="lazy"></span> is capital, and <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle f}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>f</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle f}</annotation>
</semantics>
</math></span><img src="./132e57acb643253e7810ee9702d9581f159a1c61.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:1.279ex; height:2.509ex;" alt="{\displaystyle f}" loading="lazy"></span> is a <a href="Production_function" title="Production function">production function</a> satisfying the <a href="Inada_conditions" title="Inada conditions">Inada conditions</a>. An initial capital stock <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle k_{0}>0}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>k</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>0</mn>
</mrow>
</msub>
<mo>&gt;</mo>
<mn>0</mn>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle k_{0}&gt;0}</annotation>
</semantics>
</math></span><img src="./7f67a794c981fa2199ba8253071beb4e85e81461.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:6.526ex; height:2.509ex;" alt="{\displaystyle k_{0}>0}" loading="lazy"></span> is assumed.
</p><p>Let <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle c_{t}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>c</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>t</mi>
</mrow>
</msub>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle c_{t}}</annotation>
</semantics>
</math></span><img src="./93578e37f3234419a34df79845836bc0ec5ef76c.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:1.833ex; height:2.009ex;" alt="{\displaystyle c_{t}}" loading="lazy"></span> be consumption in period <span class="texhtml mvar" style="font-style:italic;">t</span>, and assume consumption yields <a href="Utility" title="Utility">utility</a> <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle u(c_{t})=\ln(c_{t})}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>u</mi>
<mo stretchy="false">(</mo>
<msub>
<mi>c</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>t</mi>
</mrow>
</msub>
<mo stretchy="false">)</mo>
<mo>=</mo>
<mi>ln</mi>
<mo>⁡<!-- ⁡ --></mo>
<mo stretchy="false">(</mo>
<msub>
<mi>c</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>t</mi>
</mrow>
</msub>
<mo stretchy="false">)</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle u(c_{t})=\ln(c_{t})}</annotation>
</semantics>
</math></span><img src="./ee41e735fa2f20ff6f93939f3fa5e7e32cbdd740.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:13.652ex; height:2.843ex;" alt="{\displaystyle u(c_{t})=\ln(c_{t})}" loading="lazy"></span> as long as the consumer lives. Assume the consumer is impatient, so that he <a href="Discounting" title="Discounting">discounts</a> future utility by a factor <span class="texhtml mvar" style="font-style:italic;">b</span> each period, where <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle 0<b<1}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mn>0</mn>
<mo>&lt;</mo>
<mi>b</mi>
<mo>&lt;</mo>
<mn>1</mn>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle 0&lt;b&lt;1}</annotation>
</semantics>
</math></span><img src="./294830b3b4756ac60e95f53d49920ac8e2a1a227.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:9.519ex; height:2.176ex;" alt="{\displaystyle 0<b<1}" loading="lazy"></span>. Let <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle k_{t}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>k</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>t</mi>
</mrow>
</msub>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle k_{t}}</annotation>
</semantics>
</math></span><img src="./352386366dcb1dcc184d82669513975561f2d2ae.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:2.037ex; height:2.509ex;" alt="{\displaystyle k_{t}}" loading="lazy"></span> be <a href="Capital_(economics)" title="Capital (economics)">capital</a> in period <span class="texhtml mvar" style="font-style:italic;">t</span>. Assume initial capital is a given amount <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle k_{0}>0}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>k</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>0</mn>
</mrow>
</msub>
<mo>&gt;</mo>
<mn>0</mn>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle k_{0}&gt;0}</annotation>
</semantics>
</math></span><img src="./7f67a794c981fa2199ba8253071beb4e85e81461.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:6.526ex; height:2.509ex;" alt="{\displaystyle k_{0}>0}" loading="lazy"></span>, and suppose that this period's capital and consumption determine next period's capital as <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle k_{t+1}=Ak_{t}^{a}-c_{t}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>k</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>t</mi>
<mo>+</mo>
<mn>1</mn>
</mrow>
</msub>
<mo>=</mo>
<mi>A</mi>
<msubsup>
<mi>k</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>t</mi>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mi>a</mi>
</mrow>
</msubsup>
<mo>−<!-- − --></mo>
<msub>
<mi>c</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>t</mi>
</mrow>
</msub>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle k_{t+1}=Ak_{t}^{a}-c_{t}}</annotation>
</semantics>
</math></span><img src="./8fbaf9ec3c03a2530e63919cbfa0f16d5f6d5d24.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -1.005ex; width:15.966ex; height:2.843ex;" alt="{\displaystyle k_{t+1}=Ak_{t}^{a}-c_{t}}" loading="lazy"></span>, where <span class="texhtml mvar" style="font-style:italic;">A</span> is a positive constant and <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle 0<a<1}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mn>0</mn>
<mo>&lt;</mo>
<mi>a</mi>
<mo>&lt;</mo>
<mn>1</mn>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle 0&lt;a&lt;1}</annotation>
</semantics>
</math></span><img src="./7cfd02fa239e3f0b03bda321fdc6f309e6b1d915.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:9.752ex; height:2.176ex;" alt="{\displaystyle 0<a<1}" loading="lazy"></span>. Assume capital cannot be negative. Then the consumer's decision problem can be written as follows:
</p>
<dl><dd><span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \max \sum _{t=0}^{T}b^{t}\ln(c_{t})}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mo movablelimits="true" form="prefix">max</mo>
<munderover>
<mo>∑<!-- ∑ --></mo>
<mrow class="MJX-TeXAtom-ORD">
<mi>t</mi>
<mo>=</mo>
<mn>0</mn>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mi>T</mi>
</mrow>
</munderover>
<msup>
<mi>b</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>t</mi>
</mrow>
</msup>
<mi>ln</mi>
<mo>⁡<!-- ⁡ --></mo>
<mo stretchy="false">(</mo>
<msub>
<mi>c</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>t</mi>
</mrow>
</msub>
<mo stretchy="false">)</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \max \sum _{t=0}^{T}b^{t}\ln(c_{t})}</annotation>
</semantics>
</math></span><img src="./3708ec350fe3b3d2b808439d5a36403532fc670f.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -3.005ex; width:16.247ex; height:7.343ex;" alt="{\displaystyle \max \sum _{t=0}^{T}b^{t}\ln(c_{t})}" loading="lazy"></span> subject to <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle k_{t+1}=Ak_{t}^{a}-c_{t}\geq 0}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>k</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>t</mi>
<mo>+</mo>
<mn>1</mn>
</mrow>
</msub>
<mo>=</mo>
<mi>A</mi>
<msubsup>
<mi>k</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>t</mi>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mi>a</mi>
</mrow>
</msubsup>
<mo>−<!-- − --></mo>
<msub>
<mi>c</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>t</mi>
</mrow>
</msub>
<mo>≥<!-- ≥ --></mo>
<mn>0</mn>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle k_{t+1}=Ak_{t}^{a}-c_{t}\geq 0}</annotation>
</semantics>
</math></span><img src="./4b4e82a36b50b985c6d5e7d3b766c47c0c145767.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -1.005ex; width:20.226ex; height:2.843ex;" alt="{\displaystyle k_{t+1}=Ak_{t}^{a}-c_{t}\geq 0}" loading="lazy"></span> for all <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle t=0,1,2,\ldots ,T}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>t</mi>
<mo>=</mo>
<mn>0</mn>
<mo>,</mo>
<mn>1</mn>
<mo>,</mo>
<mn>2</mn>
<mo>,</mo>
<mo>…<!-- … --></mo>
<mo>,</mo>
<mi>T</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle t=0,1,2,\ldots ,T}</annotation>
</semantics>
</math></span><img src="./822463c3aa8dc826ed1e78c4e68a48be0e11240d.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:16.308ex; height:2.509ex;" alt="{\displaystyle t=0,1,2,\ldots ,T}" loading="lazy"></span></dd></dl>
<p>Written this way, the problem looks complicated, because it involves solving for all the choice variables <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle c_{0},c_{1},c_{2},\ldots ,c_{T}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>c</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>0</mn>
</mrow>
</msub>
<mo>,</mo>
<msub>
<mi>c</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>1</mn>
</mrow>
</msub>
<mo>,</mo>
<msub>
<mi>c</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msub>
<mo>,</mo>
<mo>…<!-- … --></mo>
<mo>,</mo>
<msub>
<mi>c</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>T</mi>
</mrow>
</msub>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle c_{0},c_{1},c_{2},\ldots ,c_{T}}</annotation>
</semantics>
</math></span><img src="./1765ec0a05b964c6705adc51371395b41d3f151b.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:15.825ex; height:2.009ex;" alt="{\displaystyle c_{0},c_{1},c_{2},\ldots ,c_{T}}" loading="lazy"></span>. (The capital <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle k_{0}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>k</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>0</mn>
</mrow>
</msub>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle k_{0}}</annotation>
</semantics>
</math></span><img src="./eafdfeca4ead3960fca92311910970eba7ec48a1.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:2.265ex; height:2.509ex;" alt="{\displaystyle k_{0}}" loading="lazy"></span> is not a choice variable—the consumer's initial capital is taken as given.)
</p><p>The dynamic programming approach to solve this problem involves breaking it apart into a sequence of smaller decisions. To do so, we define a sequence of <i>value functions</i> <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle V_{t}(k)}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>V</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>t</mi>
</mrow>
</msub>
<mo stretchy="false">(</mo>
<mi>k</mi>
<mo stretchy="false">)</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle V_{t}(k)}</annotation>
</semantics>
</math></span><img src="./407a1673f8e20e9c13125eeb44aa463c150ac756.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:5.202ex; height:2.843ex;" alt="{\displaystyle V_{t}(k)}" loading="lazy"></span>, for <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle t=0,1,2,\ldots ,T,T+1}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>t</mi>
<mo>=</mo>
<mn>0</mn>
<mo>,</mo>
<mn>1</mn>
<mo>,</mo>
<mn>2</mn>
<mo>,</mo>
<mo>…<!-- … --></mo>
<mo>,</mo>
<mi>T</mi>
<mo>,</mo>
<mi>T</mi>
<mo>+</mo>
<mn>1</mn>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle t=0,1,2,\ldots ,T,T+1}</annotation>
</semantics>
</math></span><img src="./2d53c4539a603e5e4696dafaa6ef98470c7658e8.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:22.981ex; height:2.509ex;" alt="{\displaystyle t=0,1,2,\ldots ,T,T+1}" loading="lazy"></span> which represent the value of having any amount of capital <span class="texhtml mvar" style="font-style:italic;">k</span> at each time <span class="texhtml mvar" style="font-style:italic;">t</span>. There is (by assumption) no utility from having capital after death, <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle V_{T+1}(k)=0}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>V</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>T</mi>
<mo>+</mo>
<mn>1</mn>
</mrow>
</msub>
<mo stretchy="false">(</mo>
<mi>k</mi>
<mo stretchy="false">)</mo>
<mo>=</mo>
<mn>0</mn>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle V_{T+1}(k)=0}</annotation>
</semantics>
</math></span><img src="./6a883a897edf0530feb7d060b9ab860df7013dcb.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:12.126ex; height:2.843ex;" alt="{\displaystyle V_{T+1}(k)=0}" loading="lazy"></span>.
</p><p>The value of any quantity of capital at any previous time can be calculated by <a href="Backward_induction" title="Backward induction">backward induction</a> using the <a href="Bellman_equation" title="Bellman equation">Bellman equation</a>. In this problem, for each <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle t=0,1,2,\ldots ,T}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>t</mi>
<mo>=</mo>
<mn>0</mn>
<mo>,</mo>
<mn>1</mn>
<mo>,</mo>
<mn>2</mn>
<mo>,</mo>
<mo>…<!-- … --></mo>
<mo>,</mo>
<mi>T</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle t=0,1,2,\ldots ,T}</annotation>
</semantics>
</math></span><img src="./822463c3aa8dc826ed1e78c4e68a48be0e11240d.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:16.308ex; height:2.509ex;" alt="{\displaystyle t=0,1,2,\ldots ,T}" loading="lazy"></span>, the Bellman equation is
</p>
<dl><dd><span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle V_{t}(k_{t})\,=\,\max \left(\ln(c_{t})+bV_{t+1}(k_{t+1})\right)}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>V</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>t</mi>
</mrow>
</msub>
<mo stretchy="false">(</mo>
<msub>
<mi>k</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>t</mi>
</mrow>
</msub>
<mo stretchy="false">)</mo>
<mspace width="thinmathspace"></mspace>
<mo>=</mo>
<mspace width="thinmathspace"></mspace>
<mo movablelimits="true" form="prefix">max</mo>
<mrow>
<mo>(</mo>
<mrow>
<mi>ln</mi>
<mo>⁡<!-- ⁡ --></mo>
<mo stretchy="false">(</mo>
<msub>
<mi>c</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>t</mi>
</mrow>
</msub>
<mo stretchy="false">)</mo>
<mo>+</mo>
<mi>b</mi>
<msub>
<mi>V</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>t</mi>
<mo>+</mo>
<mn>1</mn>
</mrow>
</msub>
<mo stretchy="false">(</mo>
<msub>
<mi>k</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>t</mi>
<mo>+</mo>
<mn>1</mn>
</mrow>
</msub>
<mo stretchy="false">)</mo>
</mrow>
<mo>)</mo>
</mrow>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle V_{t}(k_{t})\,=\,\max \left(\ln(c_{t})+bV_{t+1}(k_{t+1})\right)}</annotation>
</semantics>
</math></span><img src="./199fcd39d2bf305a41b419b99f971e0512fcf07f.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:36.071ex; height:2.843ex;" alt="{\displaystyle V_{t}(k_{t})\,=\,\max \left(\ln(c_{t})+bV_{t+1}(k_{t+1})\right)}" loading="lazy"></span> subject to <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle k_{t+1}=Ak_{t}^{a}-c_{t}\geq 0}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>k</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>t</mi>
<mo>+</mo>
<mn>1</mn>
</mrow>
</msub>
<mo>=</mo>
<mi>A</mi>
<msubsup>
<mi>k</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>t</mi>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mi>a</mi>
</mrow>
</msubsup>
<mo>−<!-- − --></mo>
<msub>
<mi>c</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>t</mi>
</mrow>
</msub>
<mo>≥<!-- ≥ --></mo>
<mn>0</mn>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle k_{t+1}=Ak_{t}^{a}-c_{t}\geq 0}</annotation>
</semantics>
</math></span><img src="./4b4e82a36b50b985c6d5e7d3b766c47c0c145767.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -1.005ex; width:20.226ex; height:2.843ex;" alt="{\displaystyle k_{t+1}=Ak_{t}^{a}-c_{t}\geq 0}" loading="lazy"></span></dd></dl>
<p>This problem is much simpler than the one we wrote down before, because it involves only two decision variables, <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle c_{t}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>c</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>t</mi>
</mrow>
</msub>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle c_{t}}</annotation>
</semantics>
</math></span><img src="./93578e37f3234419a34df79845836bc0ec5ef76c.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:1.833ex; height:2.009ex;" alt="{\displaystyle c_{t}}" loading="lazy"></span> and <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle k_{t+1}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>k</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>t</mi>
<mo>+</mo>
<mn>1</mn>
</mrow>
</msub>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle k_{t+1}}</annotation>
</semantics>
</math></span><img src="./deb47bc888092c00440588520f39cd7674fc67f3.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:4.138ex; height:2.509ex;" alt="{\displaystyle k_{t+1}}" loading="lazy"></span>. Intuitively, instead of choosing his whole lifetime plan at birth, the consumer can take things one step at a time. At time <span class="texhtml mvar" style="font-style:italic;">t</span>, his current capital <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle k_{t}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>k</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>t</mi>
</mrow>
</msub>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle k_{t}}</annotation>
</semantics>
</math></span><img src="./352386366dcb1dcc184d82669513975561f2d2ae.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:2.037ex; height:2.509ex;" alt="{\displaystyle k_{t}}" loading="lazy"></span> is given, and he only needs to choose current consumption <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle c_{t}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>c</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>t</mi>
</mrow>
</msub>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle c_{t}}</annotation>
</semantics>
</math></span><img src="./93578e37f3234419a34df79845836bc0ec5ef76c.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:1.833ex; height:2.009ex;" alt="{\displaystyle c_{t}}" loading="lazy"></span> and saving <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle k_{t+1}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>k</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>t</mi>
<mo>+</mo>
<mn>1</mn>
</mrow>
</msub>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle k_{t+1}}</annotation>
</semantics>
</math></span><img src="./deb47bc888092c00440588520f39cd7674fc67f3.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:4.138ex; height:2.509ex;" alt="{\displaystyle k_{t+1}}" loading="lazy"></span>.
</p><p>To actually solve this problem, we work backwards. For simplicity, the current level of capital is denoted as <span class="texhtml mvar" style="font-style:italic;">k</span>. <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle V_{T+1}(k)}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>V</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>T</mi>
<mo>+</mo>
<mn>1</mn>
</mrow>
</msub>
<mo stretchy="false">(</mo>
<mi>k</mi>
<mo stretchy="false">)</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle V_{T+1}(k)}</annotation>
</semantics>
</math></span><img src="./b9a196ac77d6b616a927f71c12b66d017e2c3004.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:7.866ex; height:2.843ex;" alt="{\displaystyle V_{T+1}(k)}" loading="lazy"></span> is already known, so using the Bellman equation once we can calculate <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle V_{T}(k)}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>V</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>T</mi>
</mrow>
</msub>
<mo stretchy="false">(</mo>
<mi>k</mi>
<mo stretchy="false">)</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle V_{T}(k)}</annotation>
</semantics>
</math></span><img src="./44b6a3f91c5038973c2804154a674e41d0879630.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:5.765ex; height:2.843ex;" alt="{\displaystyle V_{T}(k)}" loading="lazy"></span>, and so on until we get to <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle V_{0}(k)}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>V</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>0</mn>
</mrow>
</msub>
<mo stretchy="false">(</mo>
<mi>k</mi>
<mo stretchy="false">)</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle V_{0}(k)}</annotation>
</semantics>
</math></span><img src="./a003db4fee0c2a9a4ec194326d05685c7477efbb.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:5.43ex; height:2.843ex;" alt="{\displaystyle V_{0}(k)}" loading="lazy"></span>, which is the <i>value</i> of the initial decision problem for the whole lifetime. In other words, once we know <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle V_{T-j+1}(k)}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>V</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>T</mi>
<mo>−<!-- − --></mo>
<mi>j</mi>
<mo>+</mo>
<mn>1</mn>
</mrow>
</msub>
<mo stretchy="false">(</mo>
<mi>k</mi>
<mo stretchy="false">)</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle V_{T-j+1}(k)}</annotation>
</semantics>
</math></span><img src="./6db8f2132e654ab70410558a4a4a524f21acde17.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -1.005ex; width:9.822ex; height:3.009ex;" alt="{\displaystyle V_{T-j+1}(k)}" loading="lazy"></span>, we can calculate <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle V_{T-j}(k)}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>V</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>T</mi>
<mo>−<!-- − --></mo>
<mi>j</mi>
</mrow>
</msub>
<mo stretchy="false">(</mo>
<mi>k</mi>
<mo stretchy="false">)</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle V_{T-j}(k)}</annotation>
</semantics>
</math></span><img src="./513588d928426d584bf5710fee429551b10d6882.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -1.005ex; width:7.721ex; height:3.009ex;" alt="{\displaystyle V_{T-j}(k)}" loading="lazy"></span>, which is the maximum of <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \ln(c_{T-j})+bV_{T-j+1}(Ak^{a}-c_{T-j})}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>ln</mi>
<mo>⁡<!-- ⁡ --></mo>
<mo stretchy="false">(</mo>
<msub>
<mi>c</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>T</mi>
<mo>−<!-- − --></mo>
<mi>j</mi>
</mrow>
</msub>
<mo stretchy="false">)</mo>
<mo>+</mo>
<mi>b</mi>
<msub>
<mi>V</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>T</mi>
<mo>−<!-- − --></mo>
<mi>j</mi>
<mo>+</mo>
<mn>1</mn>
</mrow>
</msub>
<mo stretchy="false">(</mo>
<mi>A</mi>
<msup>
<mi>k</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>a</mi>
</mrow>
</msup>
<mo>−<!-- − --></mo>
<msub>
<mi>c</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>T</mi>
<mo>−<!-- − --></mo>
<mi>j</mi>
</mrow>
</msub>
<mo stretchy="false">)</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \ln(c_{T-j})+bV_{T-j+1}(Ak^{a}-c_{T-j})}</annotation>
</semantics>
</math></span><img src="./2eb6fce0ec9aa1381de35a04fb87ede7bab1953f.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -1.005ex; width:31.798ex; height:3.009ex;" alt="{\displaystyle \ln(c_{T-j})+bV_{T-j+1}(Ak^{a}-c_{T-j})}" loading="lazy"></span>, where <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle c_{T-j}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>c</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>T</mi>
<mo>−<!-- − --></mo>
<mi>j</mi>
</mrow>
</msub>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle c_{T-j}}</annotation>
</semantics>
</math></span><img src="./ce06086b5fb73811c5cdf149a757d26d17b8e05c.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -1.005ex; width:4.352ex; height:2.343ex;" alt="{\displaystyle c_{T-j}}" loading="lazy"></span> is the choice variable and <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle Ak^{a}-c_{T-j}\geq 0}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>A</mi>
<msup>
<mi>k</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>a</mi>
</mrow>
</msup>
<mo>−<!-- − --></mo>
<msub>
<mi>c</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>T</mi>
<mo>−<!-- − --></mo>
<mi>j</mi>
</mrow>
</msub>
<mo>≥<!-- ≥ --></mo>
<mn>0</mn>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle Ak^{a}-c_{T-j}\geq 0}</annotation>
</semantics>
</math></span><img src="./f79d9899e1fae38097ce8bd58636ff6d2aa104bf.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -1.005ex; width:15.51ex; height:3.009ex;" alt="{\displaystyle Ak^{a}-c_{T-j}\geq 0}" loading="lazy"></span>.
</p><p>Working backwards, it can be shown that the value function at time <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle t=T-j}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>t</mi>
<mo>=</mo>
<mi>T</mi>
<mo>−<!-- − --></mo>
<mi>j</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle t=T-j}</annotation>
</semantics>
</math></span><img src="./1caddd302995dfccfcbb960068d9ff11e1da718d.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:9.373ex; height:2.509ex;" alt="{\displaystyle t=T-j}" loading="lazy"></span> is
</p>
<dl><dd><span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle V_{T-j}(k)\,=\,a\sum _{i=0}^{j}a^{i}b^{i}\ln k+v_{T-j}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>V</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>T</mi>
<mo>−<!-- − --></mo>
<mi>j</mi>
</mrow>
</msub>
<mo stretchy="false">(</mo>
<mi>k</mi>
<mo stretchy="false">)</mo>
<mspace width="thinmathspace"></mspace>
<mo>=</mo>
<mspace width="thinmathspace"></mspace>
<mi>a</mi>
<munderover>
<mo>∑<!-- ∑ --></mo>
<mrow class="MJX-TeXAtom-ORD">
<mi>i</mi>
<mo>=</mo>
<mn>0</mn>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mi>j</mi>
</mrow>
</munderover>
<msup>
<mi>a</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>i</mi>
</mrow>
</msup>
<msup>
<mi>b</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>i</mi>
</mrow>
</msup>
<mi>ln</mi>
<mo>⁡<!-- ⁡ --></mo>
<mi>k</mi>
<mo>+</mo>
<msub>
<mi>v</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>T</mi>
<mo>−<!-- − --></mo>
<mi>j</mi>
</mrow>
</msub>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle V_{T-j}(k)\,=\,a\sum _{i=0}^{j}a^{i}b^{i}\ln k+v_{T-j}}</annotation>
</semantics>
</math></span><img src="./5281df6ca448fd68a12e5b5926b7994fac524e47.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -3.005ex; width:32.017ex; height:7.343ex;" alt="{\displaystyle V_{T-j}(k)\,=\,a\sum _{i=0}^{j}a^{i}b^{i}\ln k+v_{T-j}}" loading="lazy"></span></dd></dl>
<p>where each <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle v_{T-j}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>v</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>T</mi>
<mo>−<!-- − --></mo>
<mi>j</mi>
</mrow>
</msub>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle v_{T-j}}</annotation>
</semantics>
</math></span><img src="./005245baed781ad4a253caaed4fb8dc23899e5d9.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -1.005ex; width:4.473ex; height:2.343ex;" alt="{\displaystyle v_{T-j}}" loading="lazy"></span> is a constant, and the optimal amount to consume at time <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle t=T-j}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>t</mi>
<mo>=</mo>
<mi>T</mi>
<mo>−<!-- − --></mo>
<mi>j</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle t=T-j}</annotation>
</semantics>
</math></span><img src="./1caddd302995dfccfcbb960068d9ff11e1da718d.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:9.373ex; height:2.509ex;" alt="{\displaystyle t=T-j}" loading="lazy"></span> is
</p>
<dl><dd><span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle c_{T-j}(k)\,=\,{\frac {1}{\sum _{i=0}^{j}a^{i}b^{i}}}Ak^{a}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>c</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>T</mi>
<mo>−<!-- − --></mo>
<mi>j</mi>
</mrow>
</msub>
<mo stretchy="false">(</mo>
<mi>k</mi>
<mo stretchy="false">)</mo>
<mspace width="thinmathspace"></mspace>
<mo>=</mo>
<mspace width="thinmathspace"></mspace>
<mrow class="MJX-TeXAtom-ORD">
<mfrac>
<mn>1</mn>
<mrow>
<munderover>
<mo>∑<!-- ∑ --></mo>
<mrow class="MJX-TeXAtom-ORD">
<mi>i</mi>
<mo>=</mo>
<mn>0</mn>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mi>j</mi>
</mrow>
</munderover>
<msup>
<mi>a</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>i</mi>
</mrow>
</msup>
<msup>
<mi>b</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>i</mi>
</mrow>
</msup>
</mrow>
</mfrac>
</mrow>
<mi>A</mi>
<msup>
<mi>k</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>a</mi>
</mrow>
</msup>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle c_{T-j}(k)\,=\,{\frac {1}{\sum _{i=0}^{j}a^{i}b^{i}}}Ak^{a}}</annotation>
</semantics>
</math></span><img src="./c392e9197f93e4385350c862d6b9df90de376173.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -3.338ex; width:25.705ex; height:6.676ex;" alt="{\displaystyle c_{T-j}(k)\,=\,{\frac {1}{\sum _{i=0}^{j}a^{i}b^{i}}}Ak^{a}}" loading="lazy"></span></dd></dl>
<p>which can be simplified to
</p>
<dl><dd><span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle {\begin{aligned}c_{T}(k)&amp;=Ak^{a}\\c_{T-1}(k)&amp;={\frac {Ak^{a}}{1+ab}}\\c_{T-2}(k)&amp;={\frac {Ak^{a}}{1+ab+a^{2}b^{2}}}\\&amp;\dots \\c_{2}(k)&amp;={\frac {Ak^{a}}{1+ab+a^{2}b^{2}+\ldots +a^{T-2}b^{T-2}}}\\c_{1}(k)&amp;={\frac {Ak^{a}}{1+ab+a^{2}b^{2}+\ldots +a^{T-2}b^{T-2}+a^{T-1}b^{T-1}}}\\c_{0}(k)&amp;={\frac {Ak^{a}}{1+ab+a^{2}b^{2}+\ldots +a^{T-2}b^{T-2}+a^{T-1}b^{T-1}+a^{T}b^{T}}}\end{aligned}}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mrow class="MJX-TeXAtom-ORD">
<mtable columnalign="right left right left right left right left right left right left" rowspacing="3pt" columnspacing="0em 2em 0em 2em 0em 2em 0em 2em 0em 2em 0em" displaystyle="true">
<mtr>
<mtd>
<msub>
<mi>c</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>T</mi>
</mrow>
</msub>
<mo stretchy="false">(</mo>
<mi>k</mi>
<mo stretchy="false">)</mo>
</mtd>
<mtd>
<mi></mi>
<mo>=</mo>
<mi>A</mi>
<msup>
<mi>k</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>a</mi>
</mrow>
</msup>
</mtd>
</mtr>
<mtr>
<mtd>
<msub>
<mi>c</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>T</mi>
<mo>−<!-- − --></mo>
<mn>1</mn>
</mrow>
</msub>
<mo stretchy="false">(</mo>
<mi>k</mi>
<mo stretchy="false">)</mo>
</mtd>
<mtd>
<mi></mi>
<mo>=</mo>
<mrow class="MJX-TeXAtom-ORD">
<mfrac>
<mrow>
<mi>A</mi>
<msup>
<mi>k</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>a</mi>
</mrow>
</msup>
</mrow>
<mrow>
<mn>1</mn>
<mo>+</mo>
<mi>a</mi>
<mi>b</mi>
</mrow>
</mfrac>
</mrow>
</mtd>
</mtr>
<mtr>
<mtd>
<msub>
<mi>c</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>T</mi>
<mo>−<!-- − --></mo>
<mn>2</mn>
</mrow>
</msub>
<mo stretchy="false">(</mo>
<mi>k</mi>
<mo stretchy="false">)</mo>
</mtd>
<mtd>
<mi></mi>
<mo>=</mo>
<mrow class="MJX-TeXAtom-ORD">
<mfrac>
<mrow>
<mi>A</mi>
<msup>
<mi>k</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>a</mi>
</mrow>
</msup>
</mrow>
<mrow>
<mn>1</mn>
<mo>+</mo>
<mi>a</mi>
<mi>b</mi>
<mo>+</mo>
<msup>
<mi>a</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msup>
<msup>
<mi>b</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msup>
</mrow>
</mfrac>
</mrow>
</mtd>
</mtr>
<mtr>
<mtd></mtd>
<mtd>
<mi></mi>
<mo>…<!-- … --></mo>
</mtd>
</mtr>
<mtr>
<mtd>
<msub>
<mi>c</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msub>
<mo stretchy="false">(</mo>
<mi>k</mi>
<mo stretchy="false">)</mo>
</mtd>
<mtd>
<mi></mi>
<mo>=</mo>
<mrow class="MJX-TeXAtom-ORD">
<mfrac>
<mrow>
<mi>A</mi>
<msup>
<mi>k</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>a</mi>
</mrow>
</msup>
</mrow>
<mrow>
<mn>1</mn>
<mo>+</mo>
<mi>a</mi>
<mi>b</mi>
<mo>+</mo>
<msup>
<mi>a</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msup>
<msup>
<mi>b</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msup>
<mo>+</mo>
<mo>…<!-- … --></mo>
<mo>+</mo>
<msup>
<mi>a</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>T</mi>
<mo>−<!-- − --></mo>
<mn>2</mn>
</mrow>
</msup>
<msup>
<mi>b</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>T</mi>
<mo>−<!-- − --></mo>
<mn>2</mn>
</mrow>
</msup>
</mrow>
</mfrac>
</mrow>
</mtd>
</mtr>
<mtr>
<mtd>
<msub>
<mi>c</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>1</mn>
</mrow>
</msub>
<mo stretchy="false">(</mo>
<mi>k</mi>
<mo stretchy="false">)</mo>
</mtd>
<mtd>
<mi></mi>
<mo>=</mo>
<mrow class="MJX-TeXAtom-ORD">
<mfrac>
<mrow>
<mi>A</mi>
<msup>
<mi>k</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>a</mi>
</mrow>
</msup>
</mrow>
<mrow>
<mn>1</mn>
<mo>+</mo>
<mi>a</mi>
<mi>b</mi>
<mo>+</mo>
<msup>
<mi>a</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msup>
<msup>
<mi>b</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msup>
<mo>+</mo>
<mo>…<!-- … --></mo>
<mo>+</mo>
<msup>
<mi>a</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>T</mi>
<mo>−<!-- − --></mo>
<mn>2</mn>
</mrow>
</msup>
<msup>
<mi>b</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>T</mi>
<mo>−<!-- − --></mo>
<mn>2</mn>
</mrow>
</msup>
<mo>+</mo>
<msup>
<mi>a</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>T</mi>
<mo>−<!-- − --></mo>
<mn>1</mn>
</mrow>
</msup>
<msup>
<mi>b</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>T</mi>
<mo>−<!-- − --></mo>
<mn>1</mn>
</mrow>
</msup>
</mrow>
</mfrac>
</mrow>
</mtd>
</mtr>
<mtr>
<mtd>
<msub>
<mi>c</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>0</mn>
</mrow>
</msub>
<mo stretchy="false">(</mo>
<mi>k</mi>
<mo stretchy="false">)</mo>
</mtd>
<mtd>
<mi></mi>
<mo>=</mo>
<mrow class="MJX-TeXAtom-ORD">
<mfrac>
<mrow>
<mi>A</mi>
<msup>
<mi>k</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>a</mi>
</mrow>
</msup>
</mrow>
<mrow>
<mn>1</mn>
<mo>+</mo>
<mi>a</mi>
<mi>b</mi>
<mo>+</mo>
<msup>
<mi>a</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msup>
<msup>
<mi>b</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msup>
<mo>+</mo>
<mo>…<!-- … --></mo>
<mo>+</mo>
<msup>
<mi>a</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>T</mi>
<mo>−<!-- − --></mo>
<mn>2</mn>
</mrow>
</msup>
<msup>
<mi>b</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>T</mi>
<mo>−<!-- − --></mo>
<mn>2</mn>
</mrow>
</msup>
<mo>+</mo>
<msup>
<mi>a</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>T</mi>
<mo>−<!-- − --></mo>
<mn>1</mn>
</mrow>
</msup>
<msup>
<mi>b</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>T</mi>
<mo>−<!-- − --></mo>
<mn>1</mn>
</mrow>
</msup>
<mo>+</mo>
<msup>
<mi>a</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>T</mi>
</mrow>
</msup>
<msup>
<mi>b</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>T</mi>
</mrow>
</msup>
</mrow>
</mfrac>
</mrow>
</mtd>
</mtr>
</mtable>
</mrow>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle {\begin{aligned}c_{T}(k)&amp;=Ak^{a}\\c_{T-1}(k)&amp;={\frac {Ak^{a}}{1+ab}}\\c_{T-2}(k)&amp;={\frac {Ak^{a}}{1+ab+a^{2}b^{2}}}\\&amp;\dots \\c_{2}(k)&amp;={\frac {Ak^{a}}{1+ab+a^{2}b^{2}+\ldots +a^{T-2}b^{T-2}}}\\c_{1}(k)&amp;={\frac {Ak^{a}}{1+ab+a^{2}b^{2}+\ldots +a^{T-2}b^{T-2}+a^{T-1}b^{T-1}}}\\c_{0}(k)&amp;={\frac {Ak^{a}}{1+ab+a^{2}b^{2}+\ldots +a^{T-2}b^{T-2}+a^{T-1}b^{T-1}+a^{T}b^{T}}}\end{aligned}}}</annotation>
</semantics>
</math></span><img src="./605bed9d2072cc5b33e51d486f946a77470f50b0.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -17.171ex; width:63.114ex; height:35.509ex;" alt="{\displaystyle {\begin{aligned}c_{T}(k)&amp;=Ak^{a}\\c_{T-1}(k)&amp;={\frac {Ak^{a}}{1+ab}}\\c_{T-2}(k)&amp;={\frac {Ak^{a}}{1+ab+a^{2}b^{2}}}\\&amp;\dots \\c_{2}(k)&amp;={\frac {Ak^{a}}{1+ab+a^{2}b^{2}+\ldots +a^{T-2}b^{T-2}}}\\c_{1}(k)&amp;={\frac {Ak^{a}}{1+ab+a^{2}b^{2}+\ldots +a^{T-2}b^{T-2}+a^{T-1}b^{T-1}}}\\c_{0}(k)&amp;={\frac {Ak^{a}}{1+ab+a^{2}b^{2}+\ldots +a^{T-2}b^{T-2}+a^{T-1}b^{T-1}+a^{T}b^{T}}}\end{aligned}}}" loading="lazy"></span></dd></dl>
<p>We see that it is optimal to consume a larger fraction of current wealth as one gets older, finally consuming all remaining wealth in period <span class="texhtml mvar" style="font-style:italic;">T</span>, the last period of life.
</p>
<div class="mw-heading mw-heading3"><h3 id="Computer_science">Computer science</h3></div>
<p>There are two key attributes that a problem must have in order for dynamic programming to be applicable: <a href="Optimal_substructure" title="Optimal substructure">optimal substructure</a> and <a href="Overlapping_subproblem" class="mw-redirect" title="Overlapping subproblem">overlapping sub-problems</a>. If a problem can be solved by combining optimal solutions to <i>non-overlapping</i> sub-problems, the strategy is called "<a href="Divide_and_conquer_algorithm" class="mw-redirect" title="Divide and conquer algorithm">divide and conquer</a>" instead.<sup id="cite_ref-:0_1-1" class="reference"><a href="#cite_note-:0-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup> This is why <a href="Mergesort" class="mw-redirect" title="Mergesort">merge sort</a> and <a href="Quicksort" title="Quicksort">quick sort</a> are not classified as dynamic programming problems.
</p><p><i>Optimal substructure</i> means that the solution to a given optimization problem can be obtained by the combination of optimal solutions to its sub-problems. Such optimal substructures are usually described by means of <a href="Recursion" title="Recursion">recursion</a>. For example, given a graph <i>G=(V,E)</i>, the shortest path <i>p</i> from a vertex <i>u</i> to a vertex <i>v</i> exhibits optimal substructure: take any intermediate vertex <i>w</i> on this shortest path <i>p</i>. If <i>p</i> is truly the shortest path, then it can be split into sub-paths <i>p<sub>1</sub></i> from <i>u</i> to <i>w</i> and <i>p<sub>2</sub></i> from <i>w</i> to <i>v</i> such that these, in turn, are indeed the shortest paths between the corresponding vertices (by the simple cut-and-paste argument described in <i><a href="Introduction_to_Algorithms" title="Introduction to Algorithms">Introduction to Algorithms</a></i>). Hence, one can easily formulate the solution for finding shortest paths in a recursive manner, which is what the <a href="Bellman%E2%80%93Ford_algorithm" title="Bellman–Ford algorithm">Bellman–Ford algorithm</a> or the <a href="Floyd%E2%80%93Warshall_algorithm" title="Floyd–Warshall algorithm">Floyd–Warshall algorithm</a> does.
</p><p><i>Overlapping</i> sub-problems means that the space of sub-problems must be small, that is, any recursive algorithm solving the problem should solve the same sub-problems over and over, rather than generating new sub-problems. For example, consider the recursive formulation for generating the Fibonacci sequence: <i>F</i><sub><i>i</i></sub> = <i>F</i><sub><i>i</i>−1</sub> + <i>F</i><sub><i>i</i>−2</sub>, with base case <i>F</i><sub>1</sub>&nbsp;=&nbsp;<i>F</i><sub>2</sub>&nbsp;=&nbsp;1. Then <i>F</i><sub>43</sub> =&nbsp;<i>F</i><sub>42</sub>&nbsp;+&nbsp;<i>F</i><sub>41</sub>, and <i>F</i><sub>42</sub> =&nbsp;<i>F</i><sub>41</sub>&nbsp;+&nbsp;<i>F</i><sub>40</sub>. Now <i>F</i><sub>41</sub> is being solved in the recursive sub-trees of both <i>F</i><sub>43</sub> as well as <i>F</i><sub>42</sub>. Even though the total number of sub-problems is actually small (only 43 of them), we end up solving the same problems over and over if we adopt a naive recursive solution such as this. Dynamic programming takes account of this fact and solves each sub-problem only once.
</p>

<p>This can be achieved in either of two ways:<sup id="cite_ref-4" class="reference"><a href="#cite_note-4"><span class="cite-bracket">[</span>4<span class="cite-bracket">]</span></a></sup>
</p>
<ul><li><i><a href="Top-down_and_bottom-up_design" class="mw-redirect" title="Top-down and bottom-up design">Top-down approach</a></i>: This is the direct fall-out of the recursive formulation of any problem. If the solution to any problem can be formulated recursively using the solution to its sub-problems, and if its sub-problems are overlapping, then one can easily <a href="Memoize" class="mw-redirect" title="Memoize">memoize</a> or store the solutions to the sub-problems in a table (often an <a href="Array_(data_structure)" title="Array (data structure)">array</a> or <a href="Hash_table" title="Hash table">hashtable</a> in practice). Whenever we attempt to solve a new sub-problem, we first check the table to see if it is already solved. If a solution has been recorded, we can use it directly, otherwise we solve the sub-problem and add its solution to the table.</li>
<li><i><a href="Top-down_and_bottom-up_design" class="mw-redirect" title="Top-down and bottom-up design">Bottom-up approach</a></i>: Once we formulate the solution to a problem recursively as in terms of its sub-problems, we can try reformulating the problem in a bottom-up fashion: try solving the sub-problems first and use their solutions to build-on and arrive at solutions to bigger sub-problems. This is also usually done in a tabular form by iteratively generating solutions to bigger and bigger sub-problems by using the solutions to small sub-problems. For example, if we already know the values of <i>F</i><sub>41</sub> and <i>F</i><sub>40</sub>, we can directly calculate the value of <i>F</i><sub>42</sub>.</li></ul>
<p>Some <a href="Programming_language" title="Programming language">programming languages</a> can automatically <a href="Memoization" title="Memoization">memoize</a> the result of a function call with a particular set of arguments, in order to speed up <a href="Call-by-name" class="mw-redirect" title="Call-by-name">call-by-name</a> evaluation (this mechanism is referred to as <i><a href="Call-by-need" class="mw-redirect" title="Call-by-need">call-by-need</a></i>). Some languages make it possible portably (e.g. <a href="Scheme_(programming_language)" title="Scheme (programming language)">Scheme</a>, <a href="Common_Lisp" title="Common Lisp">Common Lisp</a>, <a href="Perl" title="Perl">Perl</a> or <a href="D_(programming_language)" title="D (programming language)">D</a>). Some languages have automatic <a href="Memoization" title="Memoization">memoization</a> built in, such as tabled <a href="Prolog" title="Prolog">Prolog</a> and <a href="J_(programming_language)" title="J (programming language)">J</a>, which supports memoization with the <i>M.</i> adverb.<sup id="cite_ref-5" class="reference"><a href="#cite_note-5"><span class="cite-bracket">[</span>5<span class="cite-bracket">]</span></a></sup> In any case, this is only possible for a <a href="Referentially_transparent" class="mw-redirect" title="Referentially transparent">referentially transparent</a> function. Memoization is also encountered as an easily accessible design pattern within term-rewrite based languages such as <a href="Wolfram_Language" title="Wolfram Language">Wolfram Language</a>.
</p>
<div class="mw-heading mw-heading3"><h3 id="Bioinformatics">Bioinformatics</h3></div>
<p>Dynamic programming is widely used in bioinformatics for tasks such as <a href="Sequence_alignment" title="Sequence alignment">sequence alignment</a>, <a href="Protein_folding" title="Protein folding">protein folding</a>, RNA structure prediction and protein-DNA binding. The first dynamic programming algorithms for protein-DNA binding were developed in the 1970s independently by <a href="Charles_DeLisi" title="Charles DeLisi">Charles DeLisi</a> in the US<sup id="cite_ref-6" class="reference"><a href="#cite_note-6"><span class="cite-bracket">[</span>6<span class="cite-bracket">]</span></a></sup> and by Georgii Gurskii and Alexander Zasedatelev in the <a href="Soviet_Union" title="Soviet Union">Soviet Union</a>.<sup id="cite_ref-7" class="reference"><a href="#cite_note-7"><span class="cite-bracket">[</span>7<span class="cite-bracket">]</span></a></sup> Recently these algorithms have become very popular in bioinformatics and <a href="Computational_biology" title="Computational biology">computational biology</a>, particularly in the studies of <a href="Nucleosome" title="Nucleosome">nucleosome</a> positioning and <a href="Transcription_factor" title="Transcription factor">transcription factor</a> binding.
</p>
<div class="mw-heading mw-heading2"><h2 id="Examples:_computer_algorithms">Examples: computer algorithms</h2></div>
<div class="mw-heading mw-heading3"><h3 id="Dijkstra's_algorithm_for_the_shortest_path_problem">Dijkstra's algorithm for the shortest path problem</h3></div>
<p>From a dynamic programming point of view, <a href="Dijkstra's_algorithm" title="Dijkstra's algorithm">Dijkstra's algorithm</a> for the <a href="Shortest_path_problem" title="Shortest path problem">shortest path problem</a> is a successive approximation scheme that solves the dynamic programming functional equation for the shortest path problem by the <b>Reaching</b> method.<sup id="cite_ref-sniedovich_06_8-0" class="reference"><a href="#cite_note-sniedovich_06-8"><span class="cite-bracket">[</span>8<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-denardo_03_9-0" class="reference"><a href="#cite_note-denardo_03-9"><span class="cite-bracket">[</span>9<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-sniedovich_10_10-0" class="reference"><a href="#cite_note-sniedovich_10-10"><span class="cite-bracket">[</span>10<span class="cite-bracket">]</span></a></sup>
</p><p>In fact, Dijkstra's explanation of the logic behind the algorithm,<sup id="cite_ref-11" class="reference"><a href="#cite_note-11"><span class="cite-bracket">[</span>11<span class="cite-bracket">]</span></a></sup> namely
</p>
<style data-mw-deduplicate="TemplateStyles:r1244412712">
/* start https://en.wikipedia.org/ */


.mw-parser-output .templatequote{overflow:hidden;margin:1em 0;padding:0 32px}.mw-parser-output .templatequotecite{line-height:1.5em;text-align:left;margin-top:0}@media(min-width:500px){.mw-parser-output .templatequotecite{padding-left:1.6em}}


/* end https://en.wikipedia.org/ */
</style><blockquote class="templatequote">
<p><b>Problem 2.</b> Find the path of minimum total length between two given nodes <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle P}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>P</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle P}</annotation>
</semantics>
</math></span><img src="./b4dc73bf40314945ff376bd363916a738548d40a.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.745ex; height:2.176ex;" alt="{\displaystyle P}" loading="lazy"></span> and <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle Q}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>Q</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle Q}</annotation>
</semantics>
</math></span><img src="./8752c7023b4b3286800fe3238271bbca681219ed.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:1.838ex; height:2.509ex;" alt="{\displaystyle Q}" loading="lazy"></span>.
</p><p>We use the fact that, if <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle R}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>R</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle R}</annotation>
</semantics>
</math></span><img src="./4b0bfb3769bf24d80e15374dc37b0441e2616e33.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.764ex; height:2.176ex;" alt="{\displaystyle R}" loading="lazy"></span> is a node on the minimal path from <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle P}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>P</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle P}</annotation>
</semantics>
</math></span><img src="./b4dc73bf40314945ff376bd363916a738548d40a.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.745ex; height:2.176ex;" alt="{\displaystyle P}" loading="lazy"></span> to <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle Q}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>Q</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle Q}</annotation>
</semantics>
</math></span><img src="./8752c7023b4b3286800fe3238271bbca681219ed.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:1.838ex; height:2.509ex;" alt="{\displaystyle Q}" loading="lazy"></span>, knowledge of the latter implies the knowledge of the minimal path from <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle P}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>P</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle P}</annotation>
</semantics>
</math></span><img src="./b4dc73bf40314945ff376bd363916a738548d40a.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.745ex; height:2.176ex;" alt="{\displaystyle P}" loading="lazy"></span> to <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle R}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>R</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle R}</annotation>
</semantics>
</math></span><img src="./4b0bfb3769bf24d80e15374dc37b0441e2616e33.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.764ex; height:2.176ex;" alt="{\displaystyle R}" loading="lazy"></span>.
</p>
</blockquote>
<p>is a paraphrasing of <a href="Richard_Bellman" class="mw-redirect" title="Richard Bellman">Bellman's</a> famous <a href="Principle_of_Optimality" class="mw-redirect" title="Principle of Optimality">Principle of Optimality</a> in the context of the <a href="Shortest_path_problem" title="Shortest path problem">shortest path problem</a>.
</p>
<div class="mw-heading mw-heading3"><h3 id="Fibonacci_sequence">Fibonacci sequence</h3></div>
<p>Using dynamic programming in the calculation of the <i>n</i>th member of the <a href="Fibonacci_sequence" title="Fibonacci sequence">Fibonacci sequence</a> improves its performance greatly. Here is a naïve implementation, based directly on the mathematical definition:
</p>
<pre><b>function</b> fib(n)
<b>if</b> n &lt;= 1 <b>return</b> n
<b>return</b> fib(n − 1) + fib(n − 2)
</pre>
<p>Notice that if we call, say, <code>fib(5)</code>, we produce a call tree that calls the function on the same value many different times:
</p>
<ol><li><code>fib(5)</code></li>
<li><code>fib(4) + fib(3)</code></li>
<li><code>(fib(3) + fib(2)) + (fib(2) + fib(1))</code></li>
<li><code>((fib(2) + fib(1)) + (fib(1) + fib(0))) + ((fib(1) + fib(0)) + fib(1))</code></li>
<li><code>(((fib(1) + fib(0)) + fib(1)) + (fib(1) + fib(0))) + ((fib(1) + fib(0)) + fib(1))</code></li></ol>
<p>In particular, <code>fib(2)</code> was calculated three times from scratch. In larger examples, many more values of <code>fib</code>, or <i>subproblems</i>, are recalculated, leading to an exponential time algorithm.
</p><p>Now, suppose we have a simple <a href="Associative_array" title="Associative array">map</a> object, <i>m</i>, which maps each value of <code>fib</code> that has already been calculated to its result, and we modify our function to use it and update it. The resulting function requires only <a href="Big-O_notation" class="mw-redirect" title="Big-O notation">O</a>(<i>n</i>) time instead of exponential time (but requires <a href="Big-O_notation" class="mw-redirect" title="Big-O notation">O</a>(<i>n</i>) space):
</p>
<pre><b>var</b> m&nbsp;:= <i><b>map</b></i>(0 → 0, 1 → 1)
<b>function</b> fib(n)
<b>if <i>key</i></b> n <b>is not in <i>map</i></b> m
m[n]&nbsp;:= fib(n − 1) + fib(n − 2)
<b>return</b> m[n]
</pre>
<p>This technique of saving values that have already been calculated is called <i><a href="Memoization" title="Memoization">memoization</a></i>; this is the top-down approach, since we first break the problem into subproblems and then calculate and store values.
</p><p>In the <b>bottom-up</b> approach, we calculate the smaller values of <code>fib</code> first, then build larger values from them. This method also uses O(<i>n</i>) time since it contains a loop that repeats n − 1 times, but it only takes constant (O(1)) space, in contrast to the top-down approach which requires O(<i>n</i>) space to store the map.
</p>
<pre><b>function</b> fib(n)
<b>if</b> n = 0
<b>return</b> 0
<b>else</b>
<b>var</b> previousFib&nbsp;:= 0, currentFib&nbsp;:= 1
<b>repeat</b> n − 1 <b>times</b> <i>// loop is skipped if n = 1</i>
<b>var</b> newFib&nbsp;:= previousFib + currentFib
previousFib&nbsp;:= currentFib
currentFib &nbsp;:= newFib
<b>return</b> currentFib
</pre>
<p>In both examples, we only calculate <code>fib(2)</code> one time, and then use it to calculate both <code>fib(4)</code> and <code>fib(3)</code>, instead of computing it every time either of them is evaluated.
</p>
<div class="mw-heading mw-heading3"><h3 id="A_type_of_balanced_0–1_matrix">A type of balanced 0–1 matrix</h3></div>
<style data-mw-deduplicate="TemplateStyles:r1251242444">
/* start https://en.wikipedia.org/ */


.mw-parser-output .ambox{border:1px solid #a2a9b1;border-left:10px solid #36c;background-color:#fbfbfb;box-sizing:border-box}.mw-parser-output .ambox+link+.ambox,.mw-parser-output .ambox+link+style+.ambox,.mw-parser-output .ambox+link+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+style+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+link+.ambox{margin-top:-1px}html body.mediawiki .mw-parser-output .ambox.mbox-small-left{margin:4px 1em 4px 0;overflow:hidden;width:238px;border-collapse:collapse;font-size:88%;line-height:1.25em}.mw-parser-output .ambox-speedy{border-left:10px solid #b32424;background-color:#fee7e6}.mw-parser-output .ambox-delete{border-left:10px solid #b32424}.mw-parser-output .ambox-content{border-left:10px solid #f28500}.mw-parser-output .ambox-style{border-left:10px solid #fc3}.mw-parser-output .ambox-move{border-left:10px solid #9932cc}.mw-parser-output .ambox-protection{border-left:10px solid #a2a9b1}.mw-parser-output .ambox .mbox-text{border:none;padding:0.25em 0.5em;width:100%}.mw-parser-output .ambox .mbox-image{border:none;padding:2px 0 2px 0.5em;text-align:center}.mw-parser-output .ambox .mbox-imageright{border:none;padding:2px 0.5em 2px 0;text-align:center}.mw-parser-output .ambox .mbox-empty-cell{border:none;padding:0;width:1px}.mw-parser-output .ambox .mbox-image-div{width:52px}@media(min-width:720px){.mw-parser-output .ambox{margin:0 10%}}@media print{body.ns-0 .mw-parser-output .ambox{display:none!important}}


/* end https://en.wikipedia.org/ */
</style>
<p>Consider the problem of assigning values, either zero or one, to the positions of an <span class="texhtml"><var>n</var> × <var>n</var></span> matrix, with <span class="texhtml"><var>n</var></span> even, so that each row and each column contains exactly <span class="texhtml"><var>n</var> / 2</span> zeros and <span class="texhtml"><var>n</var> / 2</span> ones. We ask how many different assignments there are for a given <span class="texhtml mvar" style="font-style:italic;">n</span>. For example, when <span class="texhtml"><var>n</var> = 4</span>, five possible solutions are
</p>
<dl><dd><span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle {\begin{bmatrix}0&amp;1&amp;0&amp;1\\1&amp;0&amp;1&amp;0\\0&amp;1&amp;0&amp;1\\1&amp;0&amp;1&amp;0\end{bmatrix}}{\text{ and }}{\begin{bmatrix}0&amp;0&amp;1&amp;1\\0&amp;0&amp;1&amp;1\\1&amp;1&amp;0&amp;0\\1&amp;1&amp;0&amp;0\end{bmatrix}}{\text{ and }}{\begin{bmatrix}1&amp;1&amp;0&amp;0\\0&amp;0&amp;1&amp;1\\1&amp;1&amp;0&amp;0\\0&amp;0&amp;1&amp;1\end{bmatrix}}{\text{ and }}{\begin{bmatrix}1&amp;0&amp;0&amp;1\\0&amp;1&amp;1&amp;0\\0&amp;1&amp;1&amp;0\\1&amp;0&amp;0&amp;1\end{bmatrix}}{\text{ and }}{\begin{bmatrix}1&amp;1&amp;0&amp;0\\1&amp;1&amp;0&amp;0\\0&amp;0&amp;1&amp;1\\0&amp;0&amp;1&amp;1\end{bmatrix}}.}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mrow class="MJX-TeXAtom-ORD">
<mrow>
<mo>[</mo>
<mtable rowspacing="4pt" columnspacing="1em">
<mtr>
<mtd>
<mn>0</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mn>0</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
</mtr>
</mtable>
<mo>]</mo>
</mrow>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mtext>&nbsp;and&nbsp;</mtext>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mrow>
<mo>[</mo>
<mtable rowspacing="4pt" columnspacing="1em">
<mtr>
<mtd>
<mn>0</mn>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mn>0</mn>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
</mtr>
</mtable>
<mo>]</mo>
</mrow>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mtext>&nbsp;and&nbsp;</mtext>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mrow>
<mo>[</mo>
<mtable rowspacing="4pt" columnspacing="1em">
<mtr>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mn>0</mn>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mn>0</mn>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
</mtr>
</mtable>
<mo>]</mo>
</mrow>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mtext>&nbsp;and&nbsp;</mtext>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mrow>
<mo>[</mo>
<mtable rowspacing="4pt" columnspacing="1em">
<mtr>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mn>0</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mn>0</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
</mtr>
</mtable>
<mo>]</mo>
</mrow>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mtext>&nbsp;and&nbsp;</mtext>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mrow>
<mo>[</mo>
<mtable rowspacing="4pt" columnspacing="1em">
<mtr>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mn>0</mn>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mn>0</mn>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
</mtr>
</mtable>
<mo>]</mo>
</mrow>
</mrow>
<mo>.</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle {\begin{bmatrix}0&amp;1&amp;0&amp;1\\1&amp;0&amp;1&amp;0\\0&amp;1&amp;0&amp;1\\1&amp;0&amp;1&amp;0\end{bmatrix}}{\text{ and }}{\begin{bmatrix}0&amp;0&amp;1&amp;1\\0&amp;0&amp;1&amp;1\\1&amp;1&amp;0&amp;0\\1&amp;1&amp;0&amp;0\end{bmatrix}}{\text{ and }}{\begin{bmatrix}1&amp;1&amp;0&amp;0\\0&amp;0&amp;1&amp;1\\1&amp;1&amp;0&amp;0\\0&amp;0&amp;1&amp;1\end{bmatrix}}{\text{ and }}{\begin{bmatrix}1&amp;0&amp;0&amp;1\\0&amp;1&amp;1&amp;0\\0&amp;1&amp;1&amp;0\\1&amp;0&amp;0&amp;1\end{bmatrix}}{\text{ and }}{\begin{bmatrix}1&amp;1&amp;0&amp;0\\1&amp;1&amp;0&amp;0\\0&amp;0&amp;1&amp;1\\0&amp;0&amp;1&amp;1\end{bmatrix}}.}</annotation>
</semantics>
</math></span><img src="./b94984f348b2c2fd826c47dd123ea607a7d8f13b.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -5.671ex; width:97.631ex; height:12.509ex;" alt="{\displaystyle {\begin{bmatrix}0&amp;1&amp;0&amp;1\\1&amp;0&amp;1&amp;0\\0&amp;1&amp;0&amp;1\\1&amp;0&amp;1&amp;0\end{bmatrix}}{\text{ and }}{\begin{bmatrix}0&amp;0&amp;1&amp;1\\0&amp;0&amp;1&amp;1\\1&amp;1&amp;0&amp;0\\1&amp;1&amp;0&amp;0\end{bmatrix}}{\text{ and }}{\begin{bmatrix}1&amp;1&amp;0&amp;0\\0&amp;0&amp;1&amp;1\\1&amp;1&amp;0&amp;0\\0&amp;0&amp;1&amp;1\end{bmatrix}}{\text{ and }}{\begin{bmatrix}1&amp;0&amp;0&amp;1\\0&amp;1&amp;1&amp;0\\0&amp;1&amp;1&amp;0\\1&amp;0&amp;0&amp;1\end{bmatrix}}{\text{ and }}{\begin{bmatrix}1&amp;1&amp;0&amp;0\\1&amp;1&amp;0&amp;0\\0&amp;0&amp;1&amp;1\\0&amp;0&amp;1&amp;1\end{bmatrix}}.}" loading="lazy"></span></dd></dl>
<p>There are at least three possible approaches: <a href="Brute-force_search" title="Brute-force search">brute force</a>, <a href="Backtracking" title="Backtracking">backtracking</a>, and dynamic programming.
</p><p>Brute force consists of checking all assignments of zeros and ones and counting those that have balanced rows and columns (<span class="texhtml"><var>n</var> / 2</span> zeros and <span class="texhtml"><var>n</var> / 2</span> ones). As there are <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle 2^{n^{2}}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msup>
<mn>2</mn>
<mrow class="MJX-TeXAtom-ORD">
<msup>
<mi>n</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msup>
</mrow>
</msup>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle 2^{n^{2}}}</annotation>
</semantics>
</math></span><img src="./e736acf2e0b9a29d97b91a1413af326c7175f117.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:3.212ex; height:3.009ex;" alt="{\displaystyle 2^{n^{2}}}" loading="lazy"></span> possible assignments and <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle {\tbinom {n}{n/2}}^{n}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msup>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="false" scriptlevel="0">
<mrow>
<mrow class="MJX-TeXAtom-OPEN">
<mo maxsize="1.2em" minsize="1.2em">(</mo>
</mrow>
<mfrac linethickness="0">
<mi>n</mi>
<mrow>
<mi>n</mi>
<mrow class="MJX-TeXAtom-ORD">
<mo>/</mo>
</mrow>
<mn>2</mn>
</mrow>
</mfrac>
<mrow class="MJX-TeXAtom-CLOSE">
<mo maxsize="1.2em" minsize="1.2em">)</mo>
</mrow>
</mrow>
</mstyle>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mi>n</mi>
</mrow>
</msup>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle {\tbinom {n}{n/2}}^{n}}</annotation>
</semantics>
</math></span><img src="./f5f6229cccb7cb1ee2591bf551375fbc4d1b8eda.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -1.505ex; width:5.978ex; height:3.843ex;" alt="{\displaystyle {\tbinom {n}{n/2}}^{n}}" loading="lazy"></span> sensible assignments, this strategy is not practical except maybe up to <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle n=6}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>n</mi>
<mo>=</mo>
<mn>6</mn>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle n=6}</annotation>
</semantics>
</math></span><img src="./f0365f0b9f2721ed3ebb488a96d7348d978acf8f.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:5.656ex; height:2.176ex;" alt="{\displaystyle n=6}" loading="lazy"></span>.
</p><p>Backtracking for this problem consists of choosing some order of the matrix elements and recursively placing ones or zeros, while checking that in every row and column the number of elements that have not been assigned plus the number of ones or zeros are both at least <span class="texhtml"><var>n</var> / 2</span>. While more sophisticated than brute force, this approach will visit every solution once, making it impractical for <span class="texhtml"><var>n</var></span> larger than six, since the number of solutions is already <span class="nowrap">116<span style="margin-left:.25em;">963</span><span style="margin-left:.25em;">796</span><span style="margin-left:.25em;">250</span></span> for <span class="texhtml"><var>n</var></span>&nbsp;=&nbsp;8, as we shall see.
</p><p>Dynamic programming makes it possible to count the number of solutions without visiting them all. Imagine backtracking values for the first row – what information would we require about the remaining rows, in order to be able to accurately count the solutions obtained for each first row value? We consider <span class="texhtml"><var>k</var> × <var>n</var></span> boards, where <span class="texhtml">1 ≤ <var>k</var> ≤ <var>n</var></span>, whose <span class="texhtml mvar" style="font-style:italic;">k</span> rows contain <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle n/2}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>n</mi>
<mrow class="MJX-TeXAtom-ORD">
<mo>/</mo>
</mrow>
<mn>2</mn>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle n/2}</annotation>
</semantics>
</math></span><img src="./95c3931a3fa03cc98cfacd2c49a7ca35b96eaa9b.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:3.72ex; height:2.843ex;" alt="{\displaystyle n/2}" loading="lazy"></span> zeros and <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle n/2}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>n</mi>
<mrow class="MJX-TeXAtom-ORD">
<mo>/</mo>
</mrow>
<mn>2</mn>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle n/2}</annotation>
</semantics>
</math></span><img src="./95c3931a3fa03cc98cfacd2c49a7ca35b96eaa9b.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:3.72ex; height:2.843ex;" alt="{\displaystyle n/2}" loading="lazy"></span> ones. The function <i>f</i> to which <a href="Memoization" title="Memoization">memoization</a> is applied maps vectors of <i>n</i> pairs of integers to the number of admissible boards (solutions). There is one pair for each column, and its two components indicate respectively the number of zeros and ones that have yet to be placed in that column. We seek the value of <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle f((n/2,n/2),(n/2,n/2),\ldots (n/2,n/2))}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>f</mi>
<mo stretchy="false">(</mo>
<mo stretchy="false">(</mo>
<mi>n</mi>
<mrow class="MJX-TeXAtom-ORD">
<mo>/</mo>
</mrow>
<mn>2</mn>
<mo>,</mo>
<mi>n</mi>
<mrow class="MJX-TeXAtom-ORD">
<mo>/</mo>
</mrow>
<mn>2</mn>
<mo stretchy="false">)</mo>
<mo>,</mo>
<mo stretchy="false">(</mo>
<mi>n</mi>
<mrow class="MJX-TeXAtom-ORD">
<mo>/</mo>
</mrow>
<mn>2</mn>
<mo>,</mo>
<mi>n</mi>
<mrow class="MJX-TeXAtom-ORD">
<mo>/</mo>
</mrow>
<mn>2</mn>
<mo stretchy="false">)</mo>
<mo>,</mo>
<mo>…<!-- … --></mo>
<mo stretchy="false">(</mo>
<mi>n</mi>
<mrow class="MJX-TeXAtom-ORD">
<mo>/</mo>
</mrow>
<mn>2</mn>
<mo>,</mo>
<mi>n</mi>
<mrow class="MJX-TeXAtom-ORD">
<mo>/</mo>
</mrow>
<mn>2</mn>
<mo stretchy="false">)</mo>
<mo stretchy="false">)</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle f((n/2,n/2),(n/2,n/2),\ldots (n/2,n/2))}</annotation>
</semantics>
</math></span><img src="./472f2ef0a06a78167a040a874abfc17904f47aa0.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:39.114ex; height:2.843ex;" alt="{\displaystyle f((n/2,n/2),(n/2,n/2),\ldots (n/2,n/2))}" loading="lazy"></span> (<span class="texhtml mvar" style="font-style:italic;">n</span> arguments or one vector of <span class="texhtml mvar" style="font-style:italic;">n</span> elements). The process of subproblem creation involves iterating over every one of <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle {\tbinom {n}{n/2}}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="false" scriptlevel="0">
<mrow>
<mrow class="MJX-TeXAtom-OPEN">
<mo maxsize="1.2em" minsize="1.2em">(</mo>
</mrow>
<mfrac linethickness="0">
<mi>n</mi>
<mrow>
<mi>n</mi>
<mrow class="MJX-TeXAtom-ORD">
<mo>/</mo>
</mrow>
<mn>2</mn>
</mrow>
</mfrac>
<mrow class="MJX-TeXAtom-CLOSE">
<mo maxsize="1.2em" minsize="1.2em">)</mo>
</mrow>
</mrow>
</mstyle>
</mrow>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle {\tbinom {n}{n/2}}}</annotation>
</semantics>
</math></span><img src="./a06cfa2b8e18128d5642221d7347ee97cb3ba0bd.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -1.505ex; width:4.76ex; height:3.676ex;" alt="{\displaystyle {\tbinom {n}{n/2}}}" loading="lazy"></span> possible assignments for the top row of the board, and going through every column, subtracting one from the appropriate element of the pair for that column, depending on whether the assignment for the top row contained a zero or a one at that position. If any one of the results is negative, then the assignment is invalid and does not contribute to the set of solutions (recursion stops). Otherwise, we have an assignment for the top row of the <span class="texhtml"><var>k</var> × <var>n</var></span> board and recursively compute the number of solutions to the remaining <span class="texhtml">(<var>k</var> − 1) × <var>n</var></span> board, adding the numbers of solutions for every admissible assignment of the top row and returning the sum, which is being memoized. The base case is the trivial subproblem, which occurs for a <span class="texhtml">1 × <var>n</var></span> board. The number of solutions for this board is either zero or one, depending on whether the vector is a permutation of <span class="texhtml"><var>n</var> / 2</span> <span class="texhtml">(0, 1)</span> and <span class="texhtml"><var>n</var> / 2</span> <span class="texhtml">(1, 0)</span> pairs or not.
</p><p>For example, in the first two boards shown above the sequences of vectors would be
</p>
<pre>((2, 2) (2, 2) (2, 2) (2, 2)) ((2, 2) (2, 2) (2, 2) (2, 2)) k = 4
0 1 0 1 0 0 1 1

((1, 2) (2, 1) (1, 2) (2, 1)) ((1, 2) (1, 2) (2, 1) (2, 1)) k = 3
1 0 1 0 0 0 1 1

((1, 1) (1, 1) (1, 1) (1, 1)) ((0, 2) (0, 2) (2, 0) (2, 0)) k = 2
0 1 0 1 1 1 0 0

((0, 1) (1, 0) (0, 1) (1, 0)) ((0, 1) (0, 1) (1, 0) (1, 0)) k = 1
1 0 1 0 1 1 0 0

((0, 0) (0, 0) (0, 0) (0, 0)) ((0, 0) (0, 0), (0, 0) (0, 0))
</pre>
<p>The number of solutions (sequence <span class="nowrap external"><a href="https://oeis.org/A058527" class="extiw external" title="oeis:A058527">A058527</a></span> in the <a href="On-Line_Encyclopedia_of_Integer_Sequences" title="On-Line Encyclopedia of Integer Sequences">OEIS</a>) is
</p>
<dl><dd><span class="nowrap"> 1, 2, 90, <span class="nowrap">297<span style="margin-left:.25em;">200</span></span>, <span class="nowrap">116<span style="margin-left:.25em;">963</span><span style="margin-left:.25em;">796</span><span style="margin-left:.25em;">250</span></span>, <span class="nowrap">6<span style="margin-left:.25em;">736</span><span style="margin-left:.25em;">218</span><span style="margin-left:.25em;">287</span><span style="margin-left:.25em;">430</span><span style="margin-left:.25em;">460</span><span style="margin-left:.25em;">752</span></span>, ...</span></dd></dl>
<p>Links to the MAPLE implementation of the dynamic programming approach may be found among the <a href="#External_links">external links</a>.
</p>
<div class="mw-heading mw-heading3"><h3 id="Checkerboard">Checkerboard</h3></div>

<p>Consider a <a href="Checkerboard" title="Checkerboard">checkerboard</a> with <i>n</i> × <i>n</i> squares and a cost function <code>c(i, j)</code> which returns a cost associated with square <code>(i,j)</code> (<code><i>i</i></code> being the row, <code><i>j</i></code> being the column). For instance (on a 5 × 5 checkerboard),
</p>
<table class="wikitable" style="text-align:center">

<tbody><tr>
<th>5
</th>
<td>6</td>
<td>7</td>
<td>4</td>
<td>7</td>
<td>8
</td></tr>
<tr>
<th>4
</th>
<td>7</td>
<td>6</td>
<td>1</td>
<td>1</td>
<td>4
</td></tr>
<tr>
<th>3
</th>
<td>3</td>
<td>5</td>
<td>7</td>
<td>8</td>
<td>2
</td></tr>
<tr>
<th>2
</th>
<td>–</td>
<td>6</td>
<td>7</td>
<td>0</td>
<td>–
</td></tr>
<tr>
<th>1
</th>
<td>–</td>
<td>–</td>
<td><b>5</b></td>
<td>–</td>
<td>–
</td></tr>
<tr>
<th width="15"></th>
<th style="width:15px;">1</th>
<th style="width:15px;">2</th>
<th style="width:15px;">3</th>
<th style="width:15px;">4</th>
<th style="width:15px;">5
</th></tr></tbody></table>
<p>Thus <code>c(1, 3) = 5</code>
</p><p>Let us say there was a checker that could start at any square on the first rank (i.e., row) and you wanted to know the shortest path (the sum of the minimum costs at each visited rank) to get to the last rank; assuming the checker could move only diagonally left forward, diagonally right forward, or straight forward. That is, a checker on <code>(1,3)</code> can move to <code>(2,2)</code>, <code>(2,3)</code> or <code>(2,4)</code>.
</p>
<table class="wikitable" style="text-align:center">

<tbody><tr>
<th>5
</th>
<td></td>
<td></td>
<td></td>
<td></td>
<td>
</td></tr>
<tr>
<th>4
</th>
<td></td>
<td></td>
<td></td>
<td></td>
<td>
</td></tr>
<tr>
<th>3
</th>
<td></td>
<td></td>
<td></td>
<td></td>
<td>
</td></tr>
<tr>
<th>2
</th>
<td></td>
<td>x</td>
<td>x</td>
<td>x</td>
<td>
</td></tr>
<tr>
<th>1
</th>
<td></td>
<td></td>
<td>o</td>
<td></td>
<td>
</td></tr>
<tr>
<th width="15"></th>
<th style="width:15px;">1</th>
<th style="width:15px;">2</th>
<th style="width:15px;">3</th>
<th style="width:15px;">4</th>
<th style="width:15px;">5
</th></tr></tbody></table>
<p>This problem exhibits <b>optimal substructure</b>. That is, the solution to the entire problem relies on solutions to subproblems. Let us define a function <code>q(i, j)</code> as
</p>
<dl><dd><i>q</i>(<i>i</i>, <i>j</i>) = the minimum cost to reach square (<i>i</i>, <i>j</i>).</dd></dl>
<p>Starting at rank <code>n</code> and descending to rank <code>1</code>, we compute the value of this function for all the squares at each successive rank. Picking the square that holds the minimum value at each rank gives us the shortest path between rank <code>n</code> and rank <code>1</code>.
</p><p>The function <code>q(i, j)</code> is equal to the minimum cost to get to any of the three squares below it (since those are the only squares that can reach it) plus <code>c(i, j)</code>. For instance:
</p>
<table class="wikitable" style="text-align:center">

<tbody><tr>
<th>5
</th>
<td></td>
<td></td>
<td></td>
<td></td>
<td>
</td></tr>
<tr>
<th>4
</th>
<td></td>
<td></td>
<td>A</td>
<td></td>
<td>
</td></tr>
<tr>
<th>3
</th>
<td></td>
<td>B</td>
<td>C</td>
<td>D</td>
<td>
</td></tr>
<tr>
<th>2
</th>
<td></td>
<td></td>
<td></td>
<td></td>
<td>
</td></tr>
<tr>
<th>1
</th>
<td></td>
<td></td>
<td></td>
<td></td>
<td>
</td></tr>
<tr>
<th width="15"></th>
<th style="width:15px;">1</th>
<th style="width:15px;">2</th>
<th style="width:15px;">3</th>
<th style="width:15px;">4</th>
<th style="width:15px;">5
</th></tr></tbody></table>
<dl><dd><span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle q(A)=\min(q(B),q(C),q(D))+c(A)\,}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>q</mi>
<mo stretchy="false">(</mo>
<mi>A</mi>
<mo stretchy="false">)</mo>
<mo>=</mo>
<mo movablelimits="true" form="prefix">min</mo>
<mo stretchy="false">(</mo>
<mi>q</mi>
<mo stretchy="false">(</mo>
<mi>B</mi>
<mo stretchy="false">)</mo>
<mo>,</mo>
<mi>q</mi>
<mo stretchy="false">(</mo>
<mi>C</mi>
<mo stretchy="false">)</mo>
<mo>,</mo>
<mi>q</mi>
<mo stretchy="false">(</mo>
<mi>D</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">)</mo>
<mo>+</mo>
<mi>c</mi>
<mo stretchy="false">(</mo>
<mi>A</mi>
<mo stretchy="false">)</mo>
<mspace width="thinmathspace"></mspace>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle q(A)=\min(q(B),q(C),q(D))+c(A)\,}</annotation>
</semantics>
</math></span><img src="./1f87cb5d1cb0b215fc90cb7057249c12ead674d6.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:37.351ex; height:2.843ex;" alt="{\displaystyle q(A)=\min(q(B),q(C),q(D))+c(A)\,}" loading="lazy"></span></dd></dl>
<p>Now, let us define <code>q(i, j)</code> in somewhat more general terms:
</p>
<dl><dd><span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle q(i,j)={\begin{cases}\infty &amp;j<1{\text{ or }}j>n\\c(i,j)&amp;i=1\\\min(q(i-1,j-1),q(i-1,j),q(i-1,j+1))+c(i,j)&amp;{\text{otherwise.}}\end{cases}}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>q</mi>
<mo stretchy="false">(</mo>
<mi>i</mi>
<mo>,</mo>
<mi>j</mi>
<mo stretchy="false">)</mo>
<mo>=</mo>
<mrow class="MJX-TeXAtom-ORD">
<mrow>
<mo>{</mo>
<mtable columnalign="left left" rowspacing=".2em" columnspacing="1em" displaystyle="false">
<mtr>
<mtd>
<mi mathvariant="normal">∞<!-- ∞ --></mi>
</mtd>
<mtd>
<mi>j</mi>
<mo>&lt;</mo>
<mn>1</mn>
<mrow class="MJX-TeXAtom-ORD">
<mtext>&nbsp;or&nbsp;</mtext>
</mrow>
<mi>j</mi>
<mo>&gt;</mo>
<mi>n</mi>
</mtd>
</mtr>
<mtr>
<mtd>
<mi>c</mi>
<mo stretchy="false">(</mo>
<mi>i</mi>
<mo>,</mo>
<mi>j</mi>
<mo stretchy="false">)</mo>
</mtd>
<mtd>
<mi>i</mi>
<mo>=</mo>
<mn>1</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mo movablelimits="true" form="prefix">min</mo>
<mo stretchy="false">(</mo>
<mi>q</mi>
<mo stretchy="false">(</mo>
<mi>i</mi>
<mo>−<!-- − --></mo>
<mn>1</mn>
<mo>,</mo>
<mi>j</mi>
<mo>−<!-- − --></mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
<mo>,</mo>
<mi>q</mi>
<mo stretchy="false">(</mo>
<mi>i</mi>
<mo>−<!-- − --></mo>
<mn>1</mn>
<mo>,</mo>
<mi>j</mi>
<mo stretchy="false">)</mo>
<mo>,</mo>
<mi>q</mi>
<mo stretchy="false">(</mo>
<mi>i</mi>
<mo>−<!-- − --></mo>
<mn>1</mn>
<mo>,</mo>
<mi>j</mi>
<mo>+</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
<mo stretchy="false">)</mo>
<mo>+</mo>
<mi>c</mi>
<mo stretchy="false">(</mo>
<mi>i</mi>
<mo>,</mo>
<mi>j</mi>
<mo stretchy="false">)</mo>
</mtd>
<mtd>
<mrow class="MJX-TeXAtom-ORD">
<mtext>otherwise.</mtext>
</mrow>
</mtd>
</mtr>
</mtable>
<mo fence="true" stretchy="true" symmetric="true"></mo>
</mrow>
</mrow>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle q(i,j)={\begin{cases}\infty &amp;j&lt;1{\text{ or }}j&gt;n\\c(i,j)&amp;i=1\\\min(q(i-1,j-1),q(i-1,j),q(i-1,j+1))+c(i,j)&amp;{\text{otherwise.}}\end{cases}}}</annotation>
</semantics>
</math></span><img src="./3ce1c92a173a4aa6e57116cd8a77069c4e87cff0.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -3.671ex; width:81.055ex; height:8.509ex;" alt="{\displaystyle q(i,j)={\begin{cases}\infty &amp;j<1{\text{ or }}j>n\\c(i,j)&amp;i=1\\\min(q(i-1,j-1),q(i-1,j),q(i-1,j+1))+c(i,j)&amp;{\text{otherwise.}}\end{cases}}}" loading="lazy"></span></dd></dl>
<p>The first line of this equation deals with a board modeled as squares indexed on <code>1</code> at the lowest bound and <code>n</code> at the highest bound. The second line specifies what happens at the first rank; providing a base case. The third line, the recursion, is the important part. It represents the <code>A,B,C,D</code> terms in the example. From this definition we can derive straightforward recursive code for <code>q(i,&nbsp;j)</code>. In the following pseudocode, <code>n</code> is the size of the board, <code>c(i, j)</code> is the cost function, and <code>min()</code> returns the minimum of a number of values:
</p>
<pre><b>function</b> minCost(i, j)
<b>if</b> j &lt; 1 <b>or</b> j &gt; n
<b>return</b> infinity
<b>else if</b> i = 1
<b>return</b> c(i, j)
<b>else</b>
<b>return</b> <b>min</b>( minCost(i-1, j-1), minCost(i-1, j), minCost(i-1, j+1) ) + c(i, j)
</pre>
<p>This function only computes the path cost, not the actual path. We discuss the actual path below. This, like the Fibonacci-numbers example, is horribly slow because it too exhibits the <b>overlapping sub-problems</b> attribute. That is, it recomputes the same path costs over and over. However, we can compute it much faster in a bottom-up fashion if we store path costs in a two-dimensional array <code>q[i, j]</code> rather than using a function. This avoids recomputation; all the values needed for array <code>q[i, j]</code> are computed ahead of time only once. Precomputed values for <code>(i,j)</code> are simply looked up whenever needed.
</p><p>We also need to know what the actual shortest path is. To do this, we use another array <code>p[i, j]</code>; a <i>predecessor array</i>. This array records the path to any square <code>s</code>. The predecessor of <code>s</code> is modeled as an offset relative to the index (in <code>q[i, j]</code>) of the precomputed path cost of <code>s</code>. To reconstruct the complete path, we lookup the predecessor of <code>s</code>, then the predecessor of that square, then the predecessor of that square, and so on recursively, until we reach the starting square. Consider the following pseudocode:
</p>
<pre><b>function</b> computeShortestPathArrays()
<b>for</b> x <b>from</b> 1 <b>to</b> n
q[1, x]&nbsp;:= c(1, x)
<b>for</b> y <b>from</b> 1 <b>to</b> n
q[y, 0] &nbsp;:= infinity
q[y, n + 1]&nbsp;:= infinity
<b>for</b> y <b>from</b> 2 <b>to</b> n
<b>for</b> x <b>from</b> 1 <b>to</b> n
m&nbsp;:= min(q[y-1, x-1], q[y-1, x], q[y-1, x+1])
q[y, x]&nbsp;:= m + c(y, x)
<b>if</b> m = q[y-1, x-1]
p[y, x]&nbsp;:= -1
<b>else if</b> m = q[y-1, x]
p[y, x]&nbsp;:= 0
<b>else</b>
p[y, x]&nbsp;:= 1
</pre>
<p>Now the rest is a simple matter of finding the minimum and printing it.
</p>
<pre><b>function</b> computeShortestPath()
computeShortestPathArrays()
minIndex&nbsp;:= 1
min&nbsp;:= q[n, 1]
<b>for</b> i <b>from</b> 2 <b>to</b> n
<b>if</b> q[n, i] &lt; min
minIndex&nbsp;:= i
min&nbsp;:= q[n, i]
printPath(n, minIndex)
</pre>
<pre><b>function</b> printPath(y, x)
<b>print</b>(x)
<b>print</b>("&lt;-")
<b>if</b> y = 2
<b>print</b>(x + p[y, x])
<b>else</b>
printPath(y-1, x + p[y, x])
</pre>
<div class="mw-heading mw-heading3"><h3 id="Sequence_alignment">Sequence alignment</h3></div>
<p>In <a href="Genetics" title="Genetics">genetics</a>, <a href="Sequence_alignment" title="Sequence alignment">sequence alignment</a> is an important application where dynamic programming is essential.<sup id="cite_ref-Eddy_12-0" class="reference"><a href="#cite_note-Eddy-12"><span class="cite-bracket">[</span>12<span class="cite-bracket">]</span></a></sup> Typically, the problem consists of transforming one sequence into another using edit operations that replace, insert, or remove an element. Each operation has an associated cost, and the goal is to find the <a href="Edit_distance" title="Edit distance">sequence of edits with the lowest total cost</a>.
</p><p>The problem can be stated naturally as a recursion, a sequence A is optimally edited into a sequence B by either:
</p>
<ol><li>inserting the first character of B, and performing an optimal alignment of A and the tail of B</li>
<li>deleting the first character of A, and performing the optimal alignment of the tail of A and B</li>
<li>replacing the first character of A with the first character of B, and performing optimal alignments of the tails of A and B.</li></ol>
<p>The partial alignments can be tabulated in a matrix, where cell (i,j) contains the cost of the optimal alignment of A[1..i] to B[1..j]. The cost in cell (i,j) can be calculated by adding the cost of the relevant operations to the cost of its neighboring cells, and selecting the optimum.
</p><p>Different variants exist, see <a href="Smith%E2%80%93Waterman_algorithm" title="Smith–Waterman algorithm">Smith–Waterman algorithm</a> and <a href="Needleman%E2%80%93Wunsch_algorithm" title="Needleman–Wunsch algorithm">Needleman–Wunsch algorithm</a>.
</p>
<div class="mw-heading mw-heading3"><h3 id="Tower_of_Hanoi_puzzle">Tower of Hanoi puzzle</h3></div>


<p>The <b><a href="Tower_of_Hanoi" title="Tower of Hanoi">Tower of Hanoi</a></b> or <b>Towers of <a href="Hanoi" title="Hanoi">Hanoi</a></b> is a <a href="Mathematical_game" title="Mathematical game">mathematical game</a> or <a href="Puzzle" title="Puzzle">puzzle</a>. It consists of three rods, and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus making a conical shape.
</p><p>The objective of the puzzle is to move the entire stack to another rod, obeying the following rules:
</p>
<ul><li>Only one disk may be moved at a time.</li>
<li>Each move consists of taking the upper disk from one of the rods and sliding it onto another rod, on top of the other disks that may already be present on that rod.</li>
<li>No disk may be placed on top of a smaller disk.</li></ul>
<p>The dynamic programming solution consists of solving the <a href="Bellman_equation" title="Bellman equation">functional equation</a>
</p>
<dl><dd>S(n,h,t) = S(n-1,h, not(h,t))&nbsp;; S(1,h,t)&nbsp;; S(n-1,not(h,t),t)</dd></dl>
<p>where n denotes the number of disks to be moved, h denotes the home rod, t denotes the target rod, not(h,t) denotes the third rod (neither h nor t), ";" denotes concatenation, and
</p>
<dl><dd>S(n, h, t)&nbsp;:= solution to a problem consisting of n disks that are to be moved from rod h to rod t.</dd></dl>
<p>For n=1 the problem is trivial, namely S(1,h,t) = "move a disk from rod h to rod t" (there is only one disk left).
</p><p>The number of moves required by this solution is 2<sup><i>n</i></sup>&nbsp;−&nbsp;1. If the objective is to <b>maximize</b> the number of moves (without cycling) then the dynamic programming <a href="Bellman_equation" title="Bellman equation">functional equation</a> is slightly more complicated and 3<sup><i>n</i></sup>&nbsp;−&nbsp;1 moves are required.<sup id="cite_ref-13" class="reference"><a href="#cite_note-13"><span class="cite-bracket">[</span>13<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading3"><h3 id="Egg_dropping_puzzle">Egg dropping puzzle</h3></div>
<p>A famous <a href="Puzzle" title="Puzzle">puzzle</a> relates to dropping eggs from a building to determine at which height they start to break. The following is a description involving N=2 eggs and a building with H=36 floors:<sup id="cite_ref-14" class="reference"><a href="#cite_note-14"><span class="cite-bracket">[</span>14<span class="cite-bracket">]</span></a></sup>
</p>
<dl><dd>Suppose that we wish to know which stories in a 36-story building are safe to drop eggs from, and which will cause the eggs to break on landing (using <a href="U.S._English" class="mw-redirect" title="U.S. English">U.S. English</a> terminology, in which the first floor is at ground level). We make a few assumptions:</dd></dl>
<dl><dd><ul><li>An egg that survives a fall can be used again.</li>
<li>A broken egg must be discarded.</li>
<li>The effect of a fall is the same for all eggs.</li>
<li>If an egg breaks when dropped, then it would break if dropped from a higher window.</li>
<li>If an egg survives a fall, then it would survive a shorter fall.</li>
<li>It is not ruled out that the first-floor windows break eggs, nor is it ruled out that eggs can survive the 36th-floor windows.</li></ul></dd></dl>
<dl><dd>If only one egg is available and we wish to be sure of obtaining the right result, the experiment can be carried out in only one way. Drop the egg from the first-floor window; if it survives, drop it from the second-floor window. Continue upward until it breaks. In the worst case, this method may require 36 droppings. Suppose 2 eggs are available. What is the lowest number of egg-droppings that is guaranteed to work in all cases?</dd></dl>
<p>To derive a dynamic programming <a href="Bellman_equation" title="Bellman equation">functional equation</a> for this puzzle, let the <b>state</b> of the dynamic programming model be a pair s = (n,k), where
</p>
<dl><dd><i>n</i> = number of test eggs available, <i>n</i> = 0, 1, 2, 3, ..., <i>N</i>&nbsp;−&nbsp;1.</dd>
<dd><i>k</i> = number of (consecutive) floors yet to be tested, <i>k</i> = 0, 1, 2, ..., <i>H</i>&nbsp;−&nbsp;1.</dd></dl>
<p>For instance, <i>s</i> = (2,6) indicates that two test eggs are available and 6 (consecutive) floors are yet to be tested. The initial state of the process is <i>s</i> = (<i>N</i>,<i>H</i>) where <i>N</i> denotes the number of test eggs available at the commencement of the experiment. The process terminates either when there are no more test eggs (<i>n</i> = 0) or when <i>k</i> = 0, whichever occurs first. If termination occurs at state <i>s</i> = (0,<i>k</i>) and <i>k</i>&nbsp;&gt;&nbsp;0, then the test failed.
</p><p>Now, let
</p>
<dl><dd><i>W</i>(<i>n</i>,<i>k</i>) = minimum number of trials required to identify the value of the critical floor under the worst-case scenario given that the process is in state <i>s</i> = (<i>n</i>,<i>k</i>).</dd></dl>
<p>Then it can be shown that<sup id="cite_ref-sniedovich_03_15-0" class="reference"><a href="#cite_note-sniedovich_03-15"><span class="cite-bracket">[</span>15<span class="cite-bracket">]</span></a></sup>
</p>
<dl><dd><i>W</i>(<i>n</i>,<i>k</i>) = 1 + min{max(<i>W</i>(<i>n</i> − 1, <i>x</i> − 1), <i>W</i>(<i>n</i>,<i>k</i> − <i>x</i>)): <i>x</i> = 1, 2, ..., <i>k</i> }</dd></dl>
<p>with <i>W</i>(<i>n</i>,0) = 0 for all <i>n</i>&nbsp;&gt;&nbsp;0 and <i>W</i>(1,<i>k</i>) = <i>k</i> for all&nbsp;<i>k</i>. It is easy to solve this equation iteratively by systematically increasing the values of <i>n</i> and&nbsp;<i>k</i>.
</p>
<div class="mw-heading mw-heading4"><h4 id="Faster_DP_solution_using_a_different_parametrization">Faster DP solution using a different parametrization</h4></div>
<p>Notice that the above solution takes <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle O(nk^{2})}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>O</mi>
<mo stretchy="false">(</mo>
<mi>n</mi>
<msup>
<mi>k</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msup>
<mo stretchy="false">)</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle O(nk^{2})}</annotation>
</semantics>
</math></span><img src="./e60f5fcc5716f6e45e3431be1a095d2cf2334c31.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:7.243ex; height:3.176ex;" alt="{\displaystyle O(nk^{2})}" loading="lazy"></span> time with a DP solution. This can be improved to <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle O(nk\log k)}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>O</mi>
<mo stretchy="false">(</mo>
<mi>n</mi>
<mi>k</mi>
<mi>log</mi>
<mo>⁡<!-- ⁡ --></mo>
<mi>k</mi>
<mo stretchy="false">)</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle O(nk\log k)}</annotation>
</semantics>
</math></span><img src="./33f75ae11c64ad33234553ea222991a80503247b.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:11.146ex; height:2.843ex;" alt="{\displaystyle O(nk\log k)}" loading="lazy"></span> time by binary searching on the optimal <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle x}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>x</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle x}</annotation>
</semantics>
</math></span><img src="./87f9e315fd7e2ba406057a97300593c4802b53e4.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.33ex; height:1.676ex;" alt="{\displaystyle x}" loading="lazy"></span> in the above recurrence, since <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle W(n-1,x-1)}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>W</mi>
<mo stretchy="false">(</mo>
<mi>n</mi>
<mo>−<!-- − --></mo>
<mn>1</mn>
<mo>,</mo>
<mi>x</mi>
<mo>−<!-- − --></mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle W(n-1,x-1)}</annotation>
</semantics>
</math></span><img src="./a53848e9b3dd05012ea8b5477347646f6b8ef43f.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:16.009ex; height:2.843ex;" alt="{\displaystyle W(n-1,x-1)}" loading="lazy"></span> is increasing in <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle x}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>x</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle x}</annotation>
</semantics>
</math></span><img src="./87f9e315fd7e2ba406057a97300593c4802b53e4.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.33ex; height:1.676ex;" alt="{\displaystyle x}" loading="lazy"></span> while <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle W(n,k-x)}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>W</mi>
<mo stretchy="false">(</mo>
<mi>n</mi>
<mo>,</mo>
<mi>k</mi>
<mo>−<!-- − --></mo>
<mi>x</mi>
<mo stretchy="false">)</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle W(n,k-x)}</annotation>
</semantics>
</math></span><img src="./fac88404ea16085c78fc2e3fcae7c1fb52dcd367.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:12.054ex; height:2.843ex;" alt="{\displaystyle W(n,k-x)}" loading="lazy"></span> is decreasing in <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle x}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>x</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle x}</annotation>
</semantics>
</math></span><img src="./87f9e315fd7e2ba406057a97300593c4802b53e4.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.33ex; height:1.676ex;" alt="{\displaystyle x}" loading="lazy"></span>, thus a local minimum of <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \max(W(n-1,x-1),W(n,k-x))}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mo movablelimits="true" form="prefix">max</mo>
<mo stretchy="false">(</mo>
<mi>W</mi>
<mo stretchy="false">(</mo>
<mi>n</mi>
<mo>−<!-- − --></mo>
<mn>1</mn>
<mo>,</mo>
<mi>x</mi>
<mo>−<!-- − --></mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
<mo>,</mo>
<mi>W</mi>
<mo stretchy="false">(</mo>
<mi>n</mi>
<mo>,</mo>
<mi>k</mi>
<mo>−<!-- − --></mo>
<mi>x</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">)</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \max(W(n-1,x-1),W(n,k-x))}</annotation>
</semantics>
</math></span><img src="./1c7a3a09b5c5deb068627bafdef14084f84edfb3.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:35.232ex; height:2.843ex;" alt="{\displaystyle \max(W(n-1,x-1),W(n,k-x))}" loading="lazy"></span> is a global minimum. Also, by storing the optimal <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle x}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>x</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle x}</annotation>
</semantics>
</math></span><img src="./87f9e315fd7e2ba406057a97300593c4802b53e4.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.33ex; height:1.676ex;" alt="{\displaystyle x}" loading="lazy"></span> for each cell in the DP table and referring to its value for the previous cell, the optimal <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle x}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>x</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle x}</annotation>
</semantics>
</math></span><img src="./87f9e315fd7e2ba406057a97300593c4802b53e4.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.33ex; height:1.676ex;" alt="{\displaystyle x}" loading="lazy"></span> for each cell can be found in constant time, improving it to <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle O(nk)}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>O</mi>
<mo stretchy="false">(</mo>
<mi>n</mi>
<mi>k</mi>
<mo stretchy="false">)</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle O(nk)}</annotation>
</semantics>
</math></span><img src="./16feb8341ea75a7bb8b3445959360dde7686db10.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:6.189ex; height:2.843ex;" alt="{\displaystyle O(nk)}" loading="lazy"></span> time. However, there is an even faster solution that involves a different parametrization of the problem:
</p><p>Let <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle k}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>k</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle k}</annotation>
</semantics>
</math></span><img src="./c3c9a2c7b599b37105512c5d570edc034056dd40.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.211ex; height:2.176ex;" alt="{\displaystyle k}" loading="lazy"></span> be the total number of floors such that the eggs break when dropped from the <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle k}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>k</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle k}</annotation>
</semantics>
</math></span><img src="./c3c9a2c7b599b37105512c5d570edc034056dd40.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.211ex; height:2.176ex;" alt="{\displaystyle k}" loading="lazy"></span>th floor (The example above is equivalent to taking <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle k=37}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>k</mi>
<mo>=</mo>
<mn>37</mn>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle k=37}</annotation>
</semantics>
</math></span><img src="./74c4bbfe0af3dae49f18c3bf3bdec17521863b78.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:6.635ex; height:2.176ex;" alt="{\displaystyle k=37}" loading="lazy"></span>).
</p><p>Let <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle m}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>m</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle m}</annotation>
</semantics>
</math></span><img src="./0a07d98bb302f3856cbabc47b2b9016692e3f7bc.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:2.04ex; height:1.676ex;" alt="{\displaystyle m}" loading="lazy"></span> be the minimum floor from which the egg must be dropped to be broken.
</p><p>Let <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle f(t,n)}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>f</mi>
<mo stretchy="false">(</mo>
<mi>t</mi>
<mo>,</mo>
<mi>n</mi>
<mo stretchy="false">)</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle f(t,n)}</annotation>
</semantics>
</math></span><img src="./e7804efe26a61f9352144d98bd351881de5eb4f3.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:6.356ex; height:2.843ex;" alt="{\displaystyle f(t,n)}" loading="lazy"></span> be the maximum number of values of <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle m}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>m</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle m}</annotation>
</semantics>
</math></span><img src="./0a07d98bb302f3856cbabc47b2b9016692e3f7bc.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:2.04ex; height:1.676ex;" alt="{\displaystyle m}" loading="lazy"></span> that are distinguishable using <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle t}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>t</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle t}</annotation>
</semantics>
</math></span><img src="./65658b7b223af9e1acc877d848888ecdb4466560.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:0.84ex; height:2.009ex;" alt="{\displaystyle t}" loading="lazy"></span> tries and <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle n}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>n</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle n}</annotation>
</semantics>
</math></span><img src="./a601995d55609f2d9f5e233e36fbe9ea26011b3b.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.395ex; height:1.676ex;" alt="{\displaystyle n}" loading="lazy"></span> eggs.
</p><p>Then <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle f(t,0)=f(0,n)=1}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>f</mi>
<mo stretchy="false">(</mo>
<mi>t</mi>
<mo>,</mo>
<mn>0</mn>
<mo stretchy="false">)</mo>
<mo>=</mo>
<mi>f</mi>
<mo stretchy="false">(</mo>
<mn>0</mn>
<mo>,</mo>
<mi>n</mi>
<mo stretchy="false">)</mo>
<mo>=</mo>
<mn>1</mn>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle f(t,0)=f(0,n)=1}</annotation>
</semantics>
</math></span><img src="./7e9a652befc857d8b7dbb9d22f5ddc4d65115034.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:20.162ex; height:2.843ex;" alt="{\displaystyle f(t,0)=f(0,n)=1}" loading="lazy"></span> for all <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle t,n\geq 0}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>t</mi>
<mo>,</mo>
<mi>n</mi>
<mo>≥<!-- ≥ --></mo>
<mn>0</mn>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle t,n\geq 0}</annotation>
</semantics>
</math></span><img src="./3ba436d0fd3d25a6dbacc7e227a0e4558c12736a.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:7.529ex; height:2.509ex;" alt="{\displaystyle t,n\geq 0}" loading="lazy"></span>.
</p><p>Let <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle a}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>a</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle a}</annotation>
</semantics>
</math></span><img src="./ffd2487510aa438433a2579450ab2b3d557e5edc.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.23ex; height:1.676ex;" alt="{\displaystyle a}" loading="lazy"></span> be the floor from which the first egg is dropped in the optimal strategy.
</p><p>If the first egg broke, <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle m}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>m</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle m}</annotation>
</semantics>
</math></span><img src="./0a07d98bb302f3856cbabc47b2b9016692e3f7bc.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:2.04ex; height:1.676ex;" alt="{\displaystyle m}" loading="lazy"></span> is from <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle 1}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mn>1</mn>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle 1}</annotation>
</semantics>
</math></span><img src="./92d98b82a3778f043108d4e20960a9193df57cbf.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.162ex; height:2.176ex;" alt="{\displaystyle 1}" loading="lazy"></span> to <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle a}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>a</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle a}</annotation>
</semantics>
</math></span><img src="./ffd2487510aa438433a2579450ab2b3d557e5edc.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.23ex; height:1.676ex;" alt="{\displaystyle a}" loading="lazy"></span> and distinguishable using at most <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle t-1}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>t</mi>
<mo>−<!-- − --></mo>
<mn>1</mn>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle t-1}</annotation>
</semantics>
</math></span><img src="./a215d9553945bb84b3b5a79cc796fb7d6e0629f0.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.505ex; width:4.842ex; height:2.343ex;" alt="{\displaystyle t-1}" loading="lazy"></span> tries and <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle n-1}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>n</mi>
<mo>−<!-- − --></mo>
<mn>1</mn>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle n-1}</annotation>
</semantics>
</math></span><img src="./fbd0b0f32b28f51962943ee9ede4fb34198a2521.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.505ex; width:5.398ex; height:2.343ex;" alt="{\displaystyle n-1}" loading="lazy"></span> eggs.
</p><p>If the first egg did not break, <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle m}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>m</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle m}</annotation>
</semantics>
</math></span><img src="./0a07d98bb302f3856cbabc47b2b9016692e3f7bc.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:2.04ex; height:1.676ex;" alt="{\displaystyle m}" loading="lazy"></span> is from <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle a+1}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>a</mi>
<mo>+</mo>
<mn>1</mn>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle a+1}</annotation>
</semantics>
</math></span><img src="./8028f23cfdcb108712e2bc53369305574afe820b.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.505ex; width:5.233ex; height:2.343ex;" alt="{\displaystyle a+1}" loading="lazy"></span> to <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle k}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>k</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle k}</annotation>
</semantics>
</math></span><img src="./c3c9a2c7b599b37105512c5d570edc034056dd40.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.211ex; height:2.176ex;" alt="{\displaystyle k}" loading="lazy"></span> and distinguishable using <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle t-1}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>t</mi>
<mo>−<!-- − --></mo>
<mn>1</mn>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle t-1}</annotation>
</semantics>
</math></span><img src="./a215d9553945bb84b3b5a79cc796fb7d6e0629f0.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.505ex; width:4.842ex; height:2.343ex;" alt="{\displaystyle t-1}" loading="lazy"></span> tries and <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle n}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>n</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle n}</annotation>
</semantics>
</math></span><img src="./a601995d55609f2d9f5e233e36fbe9ea26011b3b.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.395ex; height:1.676ex;" alt="{\displaystyle n}" loading="lazy"></span> eggs.
</p><p>Therefore, <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle f(t,n)=f(t-1,n-1)+f(t-1,n)}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>f</mi>
<mo stretchy="false">(</mo>
<mi>t</mi>
<mo>,</mo>
<mi>n</mi>
<mo stretchy="false">)</mo>
<mo>=</mo>
<mi>f</mi>
<mo stretchy="false">(</mo>
<mi>t</mi>
<mo>−<!-- − --></mo>
<mn>1</mn>
<mo>,</mo>
<mi>n</mi>
<mo>−<!-- − --></mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
<mo>+</mo>
<mi>f</mi>
<mo stretchy="false">(</mo>
<mi>t</mi>
<mo>−<!-- − --></mo>
<mn>1</mn>
<mo>,</mo>
<mi>n</mi>
<mo stretchy="false">)</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle f(t,n)=f(t-1,n-1)+f(t-1,n)}</annotation>
</semantics>
</math></span><img src="./31dff5e6c571fd709b1291926c85d0f83a3cc4a0.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:37.016ex; height:2.843ex;" alt="{\displaystyle f(t,n)=f(t-1,n-1)+f(t-1,n)}" loading="lazy"></span>.
</p><p>Then the problem is equivalent to finding the minimum <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle x}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>x</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle x}</annotation>
</semantics>
</math></span><img src="./87f9e315fd7e2ba406057a97300593c4802b53e4.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.33ex; height:1.676ex;" alt="{\displaystyle x}" loading="lazy"></span> such that <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle f(x,n)\geq k}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>f</mi>
<mo stretchy="false">(</mo>
<mi>x</mi>
<mo>,</mo>
<mi>n</mi>
<mo stretchy="false">)</mo>
<mo>≥<!-- ≥ --></mo>
<mi>k</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle f(x,n)\geq k}</annotation>
</semantics>
</math></span><img src="./6d6a70ba7ff177596a4734983a7bd9bd6eabcc77.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:11.156ex; height:2.843ex;" alt="{\displaystyle f(x,n)\geq k}" loading="lazy"></span>.
</p><p>To do so, we could compute <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \{f(t,i):0\leq i\leq n\}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mo fence="false" stretchy="false">{</mo>
<mi>f</mi>
<mo stretchy="false">(</mo>
<mi>t</mi>
<mo>,</mo>
<mi>i</mi>
<mo stretchy="false">)</mo>
<mo>:</mo>
<mn>0</mn>
<mo>≤<!-- ≤ --></mo>
<mi>i</mi>
<mo>≤<!-- ≤ --></mo>
<mi>n</mi>
<mo fence="false" stretchy="false">}</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \{f(t,i):0\leq i\leq n\}}</annotation>
</semantics>
</math></span><img src="./15748c7135a71c9a615b1791257f385c465f1f8f.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:19.583ex; height:2.843ex;" alt="{\displaystyle \{f(t,i):0\leq i\leq n\}}" loading="lazy"></span> in order of increasing <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle t}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>t</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle t}</annotation>
</semantics>
</math></span><img src="./65658b7b223af9e1acc877d848888ecdb4466560.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:0.84ex; height:2.009ex;" alt="{\displaystyle t}" loading="lazy"></span>, which would take <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle O(nx)}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>O</mi>
<mo stretchy="false">(</mo>
<mi>n</mi>
<mi>x</mi>
<mo stretchy="false">)</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle O(nx)}</annotation>
</semantics>
</math></span><img src="./8f99a08f754120e54250a58ad896644c9e03a3a7.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:6.307ex; height:2.843ex;" alt="{\displaystyle O(nx)}" loading="lazy"></span> time.
</p><p>Thus, if we separately handle the case of <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle n=1}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>n</mi>
<mo>=</mo>
<mn>1</mn>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle n=1}</annotation>
</semantics>
</math></span><img src="./d9ec7e1edc2e6d98f5aec2a39ae5f1c99d1e1425.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:5.656ex; height:2.176ex;" alt="{\displaystyle n=1}" loading="lazy"></span>, the algorithm would take <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle O(n{\sqrt {k}})}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>O</mi>
<mo stretchy="false">(</mo>
<mi>n</mi>
<mrow class="MJX-TeXAtom-ORD">
<msqrt>
<mi>k</mi>
</msqrt>
</mrow>
<mo stretchy="false">)</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle O(n{\sqrt {k}})}</annotation>
</semantics>
</math></span><img src="./6e9eeb287cc1a095077af75af07ec794472f1e56.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:8.124ex; height:3.176ex;" alt="{\displaystyle O(n{\sqrt {k}})}" loading="lazy"></span> time.
</p><p>But the recurrence relation can in fact be solved, giving <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle f(t,n)=\sum _{i=0}^{n}{\binom {t}{i}}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>f</mi>
<mo stretchy="false">(</mo>
<mi>t</mi>
<mo>,</mo>
<mi>n</mi>
<mo stretchy="false">)</mo>
<mo>=</mo>
<munderover>
<mo>∑<!-- ∑ --></mo>
<mrow class="MJX-TeXAtom-ORD">
<mi>i</mi>
<mo>=</mo>
<mn>0</mn>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mi>n</mi>
</mrow>
</munderover>
<mrow class="MJX-TeXAtom-ORD">
<mrow>
<mrow class="MJX-TeXAtom-OPEN">
<mo maxsize="2.047em" minsize="2.047em">(</mo>
</mrow>
<mfrac linethickness="0">
<mi>t</mi>
<mi>i</mi>
</mfrac>
<mrow class="MJX-TeXAtom-CLOSE">
<mo maxsize="2.047em" minsize="2.047em">)</mo>
</mrow>
</mrow>
</mrow>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle f(t,n)=\sum _{i=0}^{n}{\binom {t}{i}}}</annotation>
</semantics>
</math></span><img src="./a4fa894a4458ee513e6188f9ecdc20ca32c6d700.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -3.005ex; width:17.457ex; height:6.843ex;" alt="{\displaystyle f(t,n)=\sum _{i=0}^{n}{\binom {t}{i}}}" loading="lazy"></span>, which can be computed in <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle O(n)}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>O</mi>
<mo stretchy="false">(</mo>
<mi>n</mi>
<mo stretchy="false">)</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle O(n)}</annotation>
</semantics>
</math></span><img src="./34109fe397fdcff370079185bfdb65826cb5565a.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:4.977ex; height:2.843ex;" alt="{\displaystyle O(n)}" loading="lazy"></span> time using the identity <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle {\binom {t}{i+1}}={\binom {t}{i}}{\frac {t-i}{i+1}}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mrow class="MJX-TeXAtom-ORD">
<mrow>
<mrow class="MJX-TeXAtom-OPEN">
<mo maxsize="2.047em" minsize="2.047em">(</mo>
</mrow>
<mfrac linethickness="0">
<mi>t</mi>
<mrow>
<mi>i</mi>
<mo>+</mo>
<mn>1</mn>
</mrow>
</mfrac>
<mrow class="MJX-TeXAtom-CLOSE">
<mo maxsize="2.047em" minsize="2.047em">)</mo>
</mrow>
</mrow>
</mrow>
<mo>=</mo>
<mrow class="MJX-TeXAtom-ORD">
<mrow>
<mrow class="MJX-TeXAtom-OPEN">
<mo maxsize="2.047em" minsize="2.047em">(</mo>
</mrow>
<mfrac linethickness="0">
<mi>t</mi>
<mi>i</mi>
</mfrac>
<mrow class="MJX-TeXAtom-CLOSE">
<mo maxsize="2.047em" minsize="2.047em">)</mo>
</mrow>
</mrow>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mfrac>
<mrow>
<mi>t</mi>
<mo>−<!-- − --></mo>
<mi>i</mi>
</mrow>
<mrow>
<mi>i</mi>
<mo>+</mo>
<mn>1</mn>
</mrow>
</mfrac>
</mrow>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle {\binom {t}{i+1}}={\binom {t}{i}}{\frac {t-i}{i+1}}}</annotation>
</semantics>
</math></span><img src="./ed0349d190cb4f5f7e913e1aec7a402cc4236a53.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -2.505ex; width:21.227ex; height:6.176ex;" alt="{\displaystyle {\binom {t}{i+1}}={\binom {t}{i}}{\frac {t-i}{i+1}}}" loading="lazy"></span> for all <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle i\geq 0}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>i</mi>
<mo>≥<!-- ≥ --></mo>
<mn>0</mn>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle i\geq 0}</annotation>
</semantics>
</math></span><img src="./405e1424cb9c4fc171c433a8e8f04b3e5938e366.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.505ex; width:5.063ex; height:2.343ex;" alt="{\displaystyle i\geq 0}" loading="lazy"></span>.
</p><p>Since <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle f(t,n)\leq f(t+1,n)}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>f</mi>
<mo stretchy="false">(</mo>
<mi>t</mi>
<mo>,</mo>
<mi>n</mi>
<mo stretchy="false">)</mo>
<mo>≤<!-- ≤ --></mo>
<mi>f</mi>
<mo stretchy="false">(</mo>
<mi>t</mi>
<mo>+</mo>
<mn>1</mn>
<mo>,</mo>
<mi>n</mi>
<mo stretchy="false">)</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle f(t,n)\leq f(t+1,n)}</annotation>
</semantics>
</math></span><img src="./55590dc7d5f4e32400bb982d37a3ac34b13f0ac6.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:19.814ex; height:2.843ex;" alt="{\displaystyle f(t,n)\leq f(t+1,n)}" loading="lazy"></span> for all <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle t\geq 0}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>t</mi>
<mo>≥<!-- ≥ --></mo>
<mn>0</mn>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle t\geq 0}</annotation>
</semantics>
</math></span><img src="./248525429e9cd266f53ab8c52d17bc206c546060.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.505ex; width:5.101ex; height:2.343ex;" alt="{\displaystyle t\geq 0}" loading="lazy"></span>, we can binary search on <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle t}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>t</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle t}</annotation>
</semantics>
</math></span><img src="./65658b7b223af9e1acc877d848888ecdb4466560.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:0.84ex; height:2.009ex;" alt="{\displaystyle t}" loading="lazy"></span> to find <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle x}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>x</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle x}</annotation>
</semantics>
</math></span><img src="./87f9e315fd7e2ba406057a97300593c4802b53e4.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.33ex; height:1.676ex;" alt="{\displaystyle x}" loading="lazy"></span>, giving an <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle O(n\log k)}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>O</mi>
<mo stretchy="false">(</mo>
<mi>n</mi>
<mi>log</mi>
<mo>⁡<!-- ⁡ --></mo>
<mi>k</mi>
<mo stretchy="false">)</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle O(n\log k)}</annotation>
</semantics>
</math></span><img src="./99e71cfbbb1dbd170050e63d7b342b07b4b014e2.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:9.934ex; height:2.843ex;" alt="{\displaystyle O(n\log k)}" loading="lazy"></span> algorithm.<sup id="cite_ref-16" class="reference"><a href="#cite_note-16"><span class="cite-bracket">[</span>16<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading3"><h3 id="Matrix_chain_multiplication">Matrix chain multiplication</h3></div>

<div role="note" class="hatnote navigation-not-searchable">Main article: <a href="Matrix_chain_multiplication" title="Matrix chain multiplication">Matrix chain multiplication</a></div>
<p>Matrix chain multiplication is a well-known example that demonstrates utility of dynamic programming. For example, engineering applications often have to multiply a chain of matrices. It is not surprising to find matrices of large dimensions, for example 100×100. Therefore, our task is to multiply matrices <span class="nowrap">⁠<span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle A_{1},A_{2},....A_{n}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>A</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>1</mn>
</mrow>
</msub>
<mo>,</mo>
<msub>
<mi>A</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msub>
<mo>,</mo>
<mo>.</mo>
<mo>.</mo>
<mo>.</mo>
<mo>.</mo>
<msub>
<mi>A</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>n</mi>
</mrow>
</msub>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle A_{1},A_{2},....A_{n}}</annotation>
</semantics>
</math></span><img src="./700b99631b28d2edc6f6cbaa915154130b0af155.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:14.76ex; height:2.509ex;" alt="{\displaystyle A_{1},A_{2},....A_{n}}" loading="lazy"></span>⁠</span>. Matrix multiplication is not commutative, but is associative; and we can multiply only two matrices at a time. So, we can multiply this chain of matrices in many different ways, for example:
</p>
<dl><dd><span class="texhtml">((<i>A</i><sub>1</sub> × <i>A</i><sub>2</sub>) × <i>A</i><sub>3</sub>) × ... <i>A<sub>n</sub></i></span></dd></dl>
<dl><dd><span class="texhtml"><i>A</i><sub>1</sub>×(((<i>A</i><sub>2</sub>×<i>A</i><sub>3</sub>)× ... ) × <i>A<sub>n</sub></i>)</span></dd></dl>
<dl><dd><span class="texhtml">(<i>A</i><sub>1</sub> × <i>A</i><sub>2</sub>) × (<i>A</i><sub>3</sub> × ... <i>A<sub>n</sub></i>)</span></dd></dl>
<p>and so on. There are numerous ways to multiply this chain of matrices. They will all produce the same final result, however they will take more or less time to compute, based on which particular matrices are multiplied. If matrix A has dimensions m×n and matrix B has dimensions n×q, then matrix C=A×B will have dimensions m×q, and will require m*n*q scalar multiplications (using a simplistic <a href="Matrix_multiplication_algorithm" title="Matrix multiplication algorithm">matrix multiplication algorithm</a> for purposes of illustration).
</p><p>For example, let us multiply matrices A, B and C. Let us assume that their dimensions are m×n, n×p, and p×s, respectively. Matrix A×B×C will be of size m×s and can be calculated in two ways shown below:
</p>
<ol><li>Ax(B×C) This order of matrix multiplication will require nps + mns scalar multiplications.</li>
<li>(A×B)×C This order of matrix multiplication will require mnp + mps scalar calculations.</li></ol>
<p>Let us assume that m = 10, n = 100, p = 10 and s = 1000. So, the first way to multiply the chain will require 1,000,000 + 1,000,000 calculations. The second way will require only 10,000 + 100,000 calculations. Obviously, the second way is faster, and we should multiply the matrices using that arrangement of parenthesis.
</p><p>Therefore, our conclusion is that the order of parenthesis matters, and that our task is to find the optimal order of parenthesis.
</p><p>At this point, we have several choices, one of which is to design a dynamic programming algorithm that will split the problem into overlapping problems and calculate the optimal arrangement of parenthesis. The dynamic programming solution is presented below.
</p><p>Let's call m[i,j] the minimum number of scalar multiplications needed to multiply a chain of matrices from matrix i to matrix j (i.e. A<sub>i</sub> × .... × A<sub>j</sub>, i.e. i&lt;=j). We split the chain at some matrix k, such that i &lt;= k &lt; j, and try to find out which combination produces minimum m[i,j].
</p><p>The formula is:
</p>
<pre> <b>if</b> i = j, m[i,j]= 0
<b>if</b> i &lt; j, m[i,j]= min over all possible values of k <span class="nowrap">(m[i,k]+m[k+1,j] + <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle p_{i-1}*p_{k}*p_{j}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>p</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>i</mi>
<mo>−<!-- − --></mo>
<mn>1</mn>
</mrow>
</msub>
<mo>∗<!-- ∗ --></mo>
<msub>
<mi>p</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>k</mi>
</mrow>
</msub>
<mo>∗<!-- ∗ --></mo>
<msub>
<mi>p</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>j</mi>
</mrow>
</msub>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle p_{i-1}*p_{k}*p_{j}}</annotation>
</semantics>
</math></span><img src="./8d0233aa2b12fda27441c58ace6c6508c917459e.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -1.005ex; margin-left: -0.089ex; width:12.886ex; height:2.343ex;" alt="{\displaystyle p_{i-1}*p_{k}*p_{j}}" loading="lazy"></span>)</span>
</pre>
<p>where <i>k</i> ranges from <i>i</i> to <i>j</i>&nbsp;−&nbsp;1.
</p>
<ul><li><span class="nowrap">⁠<span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle p_{i-1}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>p</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>i</mi>
<mo>−<!-- − --></mo>
<mn>1</mn>
</mrow>
</msub>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle p_{i-1}}</annotation>
</semantics>
</math></span><img src="./5b2743340775af529f3dc57879ef1b2c1170e5fc.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; margin-left: -0.089ex; width:4.159ex; height:2.009ex;" alt="{\displaystyle p_{i-1}}" loading="lazy"></span>⁠</span> is the row dimension of matrix i,</li>
<li><span class="nowrap">⁠<span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle p_{k}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>p</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>k</mi>
</mrow>
</msub>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle p_{k}}</annotation>
</semantics>
</math></span><img src="./01084a31964201514f3e6bd0136989e11ea6e58a.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; margin-left: -0.089ex; width:2.348ex; height:2.009ex;" alt="{\displaystyle p_{k}}" loading="lazy"></span>⁠</span> is the column dimension of matrix k,</li>
<li><span class="nowrap">⁠<span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle p_{j}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>p</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>j</mi>
</mrow>
</msub>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle p_{j}}</annotation>
</semantics>
</math></span><img src="./499e0821b28c43e9bc2a6360b937de535057bc62.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -1.005ex; margin-left: -0.089ex; width:2.169ex; height:2.343ex;" alt="{\displaystyle p_{j}}" loading="lazy"></span>⁠</span> is the column dimension of matrix j.</li></ul>
<p>This formula can be coded as shown below, where input parameter "chain" is the chain of matrices, i.e. <span class="nowrap">⁠<span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle A_{1},A_{2},...A_{n}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>A</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>1</mn>
</mrow>
</msub>
<mo>,</mo>
<msub>
<mi>A</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msub>
<mo>,</mo>
<mo>.</mo>
<mo>.</mo>
<mo>.</mo>
<msub>
<mi>A</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>n</mi>
</mrow>
</msub>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle A_{1},A_{2},...A_{n}}</annotation>
</semantics>
</math></span><img src="./31c02495cac84da30921b34c436a691ce1593868.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:13.726ex; height:2.509ex;" alt="{\displaystyle A_{1},A_{2},...A_{n}}" loading="lazy"></span>⁠</span>:
</p>
<pre><b>function</b> OptimalMatrixChainParenthesis(chain)
n = length(chain)
<b>for</b> i = 1, n
m[i,i] = 0 <i>// Since it takes no calculations to multiply one matrix</i>
<b>for</b> len = 2, n
<b>for</b> i = 1, n - len + 1
j = i + len -1
m[i,j] = infinity <i>// So that the first calculation updates</i>
<b>for</b> k = i, j-1
<span class="nowrap">q = m[i, k] + m[k+1, j] + <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle p_{i-1}*p_{k}*p_{j}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>p</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>i</mi>
<mo>−<!-- − --></mo>
<mn>1</mn>
</mrow>
</msub>
<mo>∗<!-- ∗ --></mo>
<msub>
<mi>p</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>k</mi>
</mrow>
</msub>
<mo>∗<!-- ∗ --></mo>
<msub>
<mi>p</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>j</mi>
</mrow>
</msub>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle p_{i-1}*p_{k}*p_{j}}</annotation>
</semantics>
</math></span><img src="./8d0233aa2b12fda27441c58ace6c6508c917459e.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -1.005ex; margin-left: -0.089ex; width:12.886ex; height:2.343ex;" alt="{\displaystyle p_{i-1}*p_{k}*p_{j}}" loading="lazy"></span></span>
<b>if</b> q &lt; m[i, j] <i>// The new order of parentheses is better than what we had</i>
m[i, j] = q <i>// Update</i>
s[i, j] = k <i>// Record which k to split on, i.e. where to place the parenthesis</i>
</pre>
<p>So far, we have calculated values for all possible <span class="texhtml"><i>m</i>[<i>i</i>, <i>j</i>]</span>, the minimum number of calculations to multiply a chain from matrix <i>i</i> to matrix <i>j</i>, and we have recorded the corresponding "split point"<span class="texhtml"><i>s</i>[<i>i</i>, <i>j</i>]</span>. For example, if we are multiplying chain <span class="texhtml"><i>A</i><sub>1</sub>×<i>A</i><sub>2</sub>×<i>A</i><sub>3</sub>×<i>A</i><sub>4</sub></span>, and it turns out that <span class="texhtml"><i>m</i>[1, 3] = 100</span> and <span class="texhtml"><i>s</i>[1, 3] = 2</span>, that means that the optimal placement of parenthesis for matrices 1 to 3 is <span class="nowrap">⁠<span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle (A_{1}\times A_{2})\times A_{3}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mo stretchy="false">(</mo>
<msub>
<mi>A</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>1</mn>
</mrow>
</msub>
<mo>×<!-- × --></mo>
<msub>
<mi>A</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msub>
<mo stretchy="false">)</mo>
<mo>×<!-- × --></mo>
<msub>
<mi>A</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>3</mn>
</mrow>
</msub>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle (A_{1}\times A_{2})\times A_{3}}</annotation>
</semantics>
</math></span><img src="./823afb23c31ccd1845769469c22be709f757b1a3.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:15.882ex; height:2.843ex;" alt="{\displaystyle (A_{1}\times A_{2})\times A_{3}}" loading="lazy"></span>⁠</span> and to multiply those matrices will require 100 scalar calculations.
</p><p>This algorithm will produce "tables" <i>m</i>[, ] and <i>s</i>[, ] that will have entries for all possible values of i and j. The final solution for the entire chain is m[1, n], with corresponding split at s[1, n]. Unraveling the solution will be recursive, starting from the top and continuing until we reach the base case, i.e. multiplication of single matrices.
</p><p>Therefore, the next step is to actually split the chain, i.e. to place the parenthesis where they (optimally) belong. For this purpose we could use the following algorithm:
</p>
<pre><b>function</b> PrintOptimalParenthesis(s, i, j)
<b>if</b> i = j
print "A"i
<b>else</b>
print "("
PrintOptimalParenthesis(s, i, s[i, j])
PrintOptimalParenthesis(s, s[i, j] + 1, j)
print ")"
</pre>
<p>Of course, this algorithm is not useful for actual multiplication. This algorithm is just a user-friendly way to see what the result looks like.
</p><p>To actually multiply the matrices using the proper splits, we need the following algorithm:
</p>
<div class="mw-highlight mw-highlight-lang-javascript mw-content-ltr" dir="ltr"><pre><span class="w"> </span><span class="kd">function</span><span class="w"> </span><span class="nx">MatrixChainMultiply</span><span class="p">(</span><span class="nx">chain</span><span class="w"> </span><span class="kr">from</span><span class="w"> </span><span class="mf">1</span><span class="w"> </span><span class="nx">to</span><span class="w"> </span><span class="nx">n</span><span class="p">)</span><span class="w"> </span><span class="c1">// returns the final matrix, i.e. A1×A2×... ×An</span>
<span class="w"> </span><span class="nx">OptimalMatrixChainParenthesis</span><span class="p">(</span><span class="nx">chain</span><span class="w"> </span><span class="kr">from</span><span class="w"> </span><span class="mf">1</span><span class="w"> </span><span class="nx">to</span><span class="w"> </span><span class="nx">n</span><span class="p">)</span><span class="w"> </span><span class="c1">// this will produce s[ . ] and m[ . ] "tables"</span>
<span class="w"> </span><span class="nx">OptimalMatrixMultiplication</span><span class="p">(</span><span class="nx">s</span><span class="p">,</span><span class="w"> </span><span class="nx">chain</span><span class="w"> </span><span class="kr">from</span><span class="w"> </span><span class="mf">1</span><span class="w"> </span><span class="nx">to</span><span class="w"> </span><span class="nx">n</span><span class="p">)</span><span class="w"> </span><span class="c1">// actually multiply</span>

<span class="w"> </span><span class="kd">function</span><span class="w"> </span><span class="nx">OptimalMatrixMultiplication</span><span class="p">(</span><span class="nx">s</span><span class="p">,</span><span class="w"> </span><span class="nx">i</span><span class="p">,</span><span class="w"> </span><span class="nx">j</span><span class="p">)</span><span class="w"> </span><span class="c1">// returns the result of multiplying a chain of matrices from Ai to Aj in optimal way</span>
<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="nx">i</span><span class="w"> </span><span class="o">&lt;</span><span class="w"> </span><span class="nx">j</span>
<span class="w"> </span><span class="c1">// keep on splitting the chain and multiplying the matrices in left and right sides</span>
<span class="w"> </span><span class="nx">LeftSide</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">OptimalMatrixMultiplication</span><span class="p">(</span><span class="nx">s</span><span class="p">,</span><span class="w"> </span><span class="nx">i</span><span class="p">,</span><span class="w"> </span><span class="nx">s</span><span class="p">[</span><span class="nx">i</span><span class="p">,</span><span class="w"> </span><span class="nx">j</span><span class="p">])</span>
<span class="w"> </span><span class="nx">RightSide</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">OptimalMatrixMultiplication</span><span class="p">(</span><span class="nx">s</span><span class="p">,</span><span class="w"> </span><span class="nx">s</span><span class="p">[</span><span class="nx">i</span><span class="p">,</span><span class="w"> </span><span class="nx">j</span><span class="p">]</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mf">1</span><span class="p">,</span><span class="w"> </span><span class="nx">j</span><span class="p">)</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="nx">MatrixMultiply</span><span class="p">(</span><span class="nx">LeftSide</span><span class="p">,</span><span class="w"> </span><span class="nx">RightSide</span><span class="p">)</span><span class="w"> </span>
<span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="nx">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">j</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="nx">Ai</span><span class="w"> </span><span class="c1">// matrix at position i</span>
<span class="w"> </span><span class="k">else</span><span class="w"> </span>
<span class="w"> </span><span class="nx">print</span><span class="w"> </span><span class="s2">"error, i &lt;= j must hold"</span>

<span class="w"> </span><span class="kd">function</span><span class="w"> </span><span class="nx">MatrixMultiply</span><span class="p">(</span><span class="nx">A</span><span class="p">,</span><span class="w"> </span><span class="nx">B</span><span class="p">)</span><span class="w"> </span><span class="c1">// function that multiplies two matrices</span>
<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="nx">columns</span><span class="p">(</span><span class="nx">A</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">rows</span><span class="p">(</span><span class="nx">B</span><span class="p">)</span><span class="w"> </span>
<span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="nx">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mf">1</span><span class="p">,</span><span class="w"> </span><span class="nx">rows</span><span class="p">(</span><span class="nx">A</span><span class="p">)</span>
<span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="nx">j</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mf">1</span><span class="p">,</span><span class="w"> </span><span class="nx">columns</span><span class="p">(</span><span class="nx">B</span><span class="p">)</span>
<span class="w"> </span><span class="nx">C</span><span class="p">[</span><span class="nx">i</span><span class="p">,</span><span class="w"> </span><span class="nx">j</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mf">0</span>
<span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="nx">k</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mf">1</span><span class="p">,</span><span class="w"> </span><span class="nx">columns</span><span class="p">(</span><span class="nx">A</span><span class="p">)</span>
<span class="w"> </span><span class="nx">C</span><span class="p">[</span><span class="nx">i</span><span class="p">,</span><span class="w"> </span><span class="nx">j</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">C</span><span class="p">[</span><span class="nx">i</span><span class="p">,</span><span class="w"> </span><span class="nx">j</span><span class="p">]</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="nx">A</span><span class="p">[</span><span class="nx">i</span><span class="p">,</span><span class="w"> </span><span class="nx">k</span><span class="p">]</span><span class="o">*</span><span class="nx">B</span><span class="p">[</span><span class="nx">k</span><span class="p">,</span><span class="w"> </span><span class="nx">j</span><span class="p">]</span><span class="w"> </span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="nx">C</span><span class="w"> </span>
<span class="w"> </span><span class="k">else</span><span class="w"> </span>
<span class="w"> </span><span class="nx">print</span><span class="w"> </span><span class="s2">"error, incompatible dimensions."</span>
</pre></div>
<div class="mw-heading mw-heading2"><h2 id="History_of_the_name">History of the name</h2></div>
<p>The term <i>dynamic programming</i> was originally used in the 1940s by <a href="Richard_Bellman" class="mw-redirect" title="Richard Bellman">Richard Bellman</a> to describe the process of solving problems where one needs to find the best decisions one after another. By 1953, he refined this to the modern meaning, referring specifically to nesting smaller decision problems inside larger decisions,<sup id="cite_ref-17" class="reference"><a href="#cite_note-17"><span class="cite-bracket">[</span>17<span class="cite-bracket">]</span></a></sup> and the field was thereafter recognized by the <a href="IEEE" class="mw-redirect" title="IEEE">IEEE</a> as a <a href="Systems_analysis" title="Systems analysis">systems analysis</a> and <a href="Engineering" title="Engineering">engineering</a> topic. Bellman's contribution is remembered in the name of the <a href="Bellman_equation" title="Bellman equation">Bellman equation</a>, a central result of dynamic programming which restates an optimization problem in <a href="Recursion_(computer_science)" title="Recursion (computer science)">recursive</a> form.
</p><p>Bellman explains the reasoning behind the term <i>dynamic programming</i> in his autobiography, <i>Eye of the Hurricane: An Autobiography</i>:
</p>
<blockquote class="templatequote"><p>I spent the Fall quarter (of 1950) at <a href="RAND_Corporation" title="RAND Corporation">RAND</a>. My first task was to find a name for multistage decision processes. An interesting question is, "Where did the name, dynamic programming, come from?" The 1950s were not good years for mathematical research. We had a very interesting gentleman in Washington named <a href="Charles_Erwin_Wilson" title="Charles Erwin Wilson">Wilson</a>. He was Secretary of Defense, and he actually had a pathological fear and hatred of the word "research". I'm not using the term lightly; I'm using it precisely. His face would suffuse, he would turn red, and he would get violent if people used the term research in his presence. You can imagine how he felt, then, about the term mathematical. The RAND Corporation was employed by the Air Force, and the Air Force had Wilson as its boss, essentially. Hence, I felt I had to do something to shield Wilson and the Air Force from the fact that I was really doing mathematics inside the RAND Corporation. What title, what name, could I choose? In the first place I was interested in planning, in decision making, in thinking. But planning, is not a good word for various reasons. I decided therefore to use the word "programming". I wanted to get across the idea that this was dynamic, this was multistage, this was time-varying. I thought, let's kill two birds with one stone. Let's take a word that has an absolutely precise meaning, namely dynamic, in the classical physical sense. It also has a very interesting property as an adjective, and that is it's impossible to use the word dynamic in a pejorative sense. Try thinking of some combination that will possibly give it a pejorative meaning. It's impossible. Thus, I thought dynamic programming was a good name. It was something not even a Congressman could object to. So I used it as an umbrella for my activities.</p></blockquote><div class="templatequotecite"><p style="display: inline; padding-left: 2.3em;">— Richard Bellman, <i>Eye of the Hurricane: An Autobiography</i> (1984, page 159)</p></div>
<p>The word <i>dynamic</i> was chosen by Bellman to capture the time-varying aspect of the problems, and because it sounded impressive.<sup id="cite_ref-Eddy_12-1" class="reference"><a href="#cite_note-Eddy-12"><span class="cite-bracket">[</span>12<span class="cite-bracket">]</span></a></sup> The word <i>programming</i> referred to the use of the method to find an optimal <i>program</i>, in the sense of a military schedule for training or logistics. This usage is the same as that in the phrases <i><a href="Linear_programming" title="Linear programming">linear programming</a></i> and <i>mathematical programming</i>, a synonym for <a href="Mathematical_optimization" title="Mathematical optimization">mathematical optimization</a>.<sup id="cite_ref-18" class="reference"><a href="#cite_note-18"><span class="cite-bracket">[</span>18<span class="cite-bracket">]</span></a></sup>
</p><p>The above explanation of the origin of the term may be inaccurate: According to Russell and Norvig, the above story "cannot be strictly true, because his first paper using the term (Bellman, 1952) appeared before Wilson became Secretary of Defense in 1953."<sup id="cite_ref-19" class="reference"><a href="#cite_note-19"><span class="cite-bracket">[</span>19<span class="cite-bracket">]</span></a></sup> Also, <a href="Harold_J._Kushner" title="Harold J. Kushner">Harold J. Kushner</a> stated in a speech that, "On the other hand, when I asked [Bellman] the same question, he replied that he was trying to upstage <a href="George_Dantzig" title="George Dantzig">Dantzig's</a> linear programming by adding dynamic. Perhaps both motivations were true."<sup id="cite_ref-20" class="reference"><a href="#cite_note-20"><span class="cite-bracket">[</span>20<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading2"><h2 id="See_also">See also</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1266661725">
/* start https://en.wikipedia.org/ */


.mw-parser-output .portalbox{padding:0;margin:0.5em 0;display:table;box-sizing:border-box;max-width:175px;list-style:none}.mw-parser-output .portalborder{border:1px solid var(--border-color-base,#a2a9b1);padding:0.1em;background:var(--background-color-neutral-subtle,#f8f9fa)}.mw-parser-output .portalbox-entry{display:table-row;font-size:85%;line-height:110%;height:1.9em;font-style:italic;font-weight:bold}.mw-parser-output .portalbox-image{display:table-cell;padding:0.2em;vertical-align:middle;text-align:center}.mw-parser-output .portalbox-link{display:table-cell;padding:0.2em 0.2em 0.2em 0.3em;vertical-align:middle}@media(min-width:720px){.mw-parser-output .portalleft{margin:0.5em 1em 0.5em 0}.mw-parser-output .portalright{clear:right;float:right;margin:0.5em 0 0.5em 1em}}


/* end https://en.wikipedia.org/ */
</style>
<style data-mw-deduplicate="TemplateStyles:r1184024115">
/* start https://en.wikipedia.org/ */


.mw-parser-output .div-col{margin-top:0.3em;column-width:30em}.mw-parser-output .div-col-small{font-size:90%}.mw-parser-output .div-col-rules{column-rule:1px solid #aaa}.mw-parser-output .div-col dl,.mw-parser-output .div-col ol,.mw-parser-output .div-col ul{margin-top:0}.mw-parser-output .div-col li,.mw-parser-output .div-col dd{page-break-inside:avoid;break-inside:avoid-column}


/* end https://en.wikipedia.org/ */
</style><div class="div-col" style="column-width: 30em;">
<ul><li><a href="Convexity_in_economics" title="Convexity in economics">Convexity in economics</a>&nbsp;– Significant topic in economics</li>
<li><a href="Greedy_algorithm" title="Greedy algorithm">Greedy algorithm</a>&nbsp;– Sequence of locally optimal choices</li>
<li><a href="Non-convexity_(economics)" title="Non-convexity (economics)">Non-convexity (economics)</a>&nbsp;– Violations of the convexity assumptions of elementary economics</li>
<li><a href="Stochastic_programming" title="Stochastic programming">Stochastic programming</a>&nbsp;– Framework for modeling optimization problems that involve uncertainty</li>
<li><a href="Stochastic_dynamic_programming" title="Stochastic dynamic programming">Stochastic dynamic programming</a>&nbsp;– 1957 technique for modelling problems of decision making under uncertainty</li>
<li><a href="Reinforcement_learning" title="Reinforcement learning">Reinforcement learning</a>&nbsp;– Field of machine learning</li></ul>
</div>
<div class="mw-heading mw-heading2"><h2 id="References">References</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1239543626">
/* start https://en.wikipedia.org/ */


.mw-parser-output .reflist{margin-bottom:0.5em;list-style-type:decimal}@media screen{.mw-parser-output .reflist{font-size:90%}}.mw-parser-output .reflist .references{font-size:100%;margin-bottom:0;list-style-type:inherit}.mw-parser-output .reflist-columns-2{column-width:30em}.mw-parser-output .reflist-columns-3{column-width:25em}.mw-parser-output .reflist-columns{margin-top:0.3em}.mw-parser-output .reflist-columns ol{margin-top:0}.mw-parser-output .reflist-columns li{page-break-inside:avoid;break-inside:avoid-column}.mw-parser-output .reflist-upper-alpha{list-style-type:upper-alpha}.mw-parser-output .reflist-upper-roman{list-style-type:upper-roman}.mw-parser-output .reflist-lower-alpha{list-style-type:lower-alpha}.mw-parser-output .reflist-lower-greek{list-style-type:lower-greek}.mw-parser-output .reflist-lower-roman{list-style-type:lower-roman}


/* end https://en.wikipedia.org/ */
</style><div class="reflist">
<div class="mw-references-wrap mw-references-columns"><ol class="references">
<li id="cite_note-:0-1"><span class="mw-cite-backlink">^ <a href="#cite_ref-:0_1-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-:0_1-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text">Cormen, T. H.; Leiserson, C. E.; Rivest, R. L.; Stein, C. (2001), Introduction to Algorithms (2nd ed.), MIT Press &amp; McGraw–Hill, <style data-mw-deduplicate="TemplateStyles:r1238218222">
/* start https://en.wikipedia.org/ */


.mw-parser-output cite.citation{font-style:inherit;word-wrap:break-word}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}.mw-parser-output .id-lock-free.id-lock-free a{background:url("./mw/Lock-green.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-limited.id-lock-limited a,.mw-parser-output .id-lock-registration.id-lock-registration a{background:url("./mw/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-subscription.id-lock-subscription a{background:url("./mw/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .cs1-ws-icon a{background:url("./mw/Wikisource-logo.svg")right 0.1em center/12px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-free a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-limited a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-registration a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-subscription a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .cs1-ws-icon a{background-size:contain;padding:0 1em 0 0}.mw-parser-output .cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;color:var(--color-error,#d33)}.mw-parser-output .cs1-visible-error{color:var(--color-error,#d33)}.mw-parser-output .cs1-maint{display:none;color:#085;margin-left:0.3em}.mw-parser-output .cs1-kern-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}@media screen{.mw-parser-output .cs1-format{font-size:95%}html.skin-theme-clientpref-night .mw-parser-output .cs1-maint{color:#18911f}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .cs1-maint{color:#18911f}}


/* end https://en.wikipedia.org/ */
</style><a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>0-262-03293-7</bdi> . pp. 344.</span>
</li>
<li id="cite_note-2"><span class="mw-cite-backlink"><b><a href="#cite_ref-2">^</a></b></span> <span class="reference-text"><cite id="CITEREFKamienSchwartz1991" class="citation book cs1"><a href="Morton_Kamien" title="Morton Kamien">Kamien, M. I.</a>; <a href="Nancy_Schwartz" class="mw-redirect" title="Nancy Schwartz">Schwartz, N. L.</a> (1991). <a rel="nofollow" class="external text" href="https://books.google.com/books?id=0IoGUn8wjDQC&amp;pg=PA261"><i>Dynamic Optimization: The Calculus of Variations and Optimal Control in Economics and Management</i></a> (Second&nbsp;ed.). New York: Elsevier. p.&nbsp;261. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>978-0-444-01609-6</bdi>.</cite></span>
</li>
<li id="cite_note-3"><span class="mw-cite-backlink"><b><a href="#cite_ref-3">^</a></b></span> <span class="reference-text"><cite id="CITEREFKirk1970" class="citation book cs1">Kirk, Donald E. (1970). <a rel="nofollow" class="external text" href="https://books.google.com/books?id=fCh2SAtWIdwC&amp;pg=PA94"><i>Optimal Control Theory: An Introduction</i></a>. Englewood Cliffs, NJ: Prentice-Hall. pp.&nbsp;<span class="nowrap">94–</span>95. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>978-0-13-638098-6</bdi>.</cite></span>
</li>
<li id="cite_note-4"><span class="mw-cite-backlink"><b><a href="#cite_ref-4">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://jeffe.cs.illinois.edu/teaching/algorithms/">"Algorithms by Jeff Erickson"</a>. <i>jeffe.cs.illinois.edu</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2024-12-06</span></span>.</cite></span>
</li>
<li id="cite_note-5"><span class="mw-cite-backlink"><b><a href="#cite_ref-5">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://www.jsoftware.com/help/dictionary/dmcapdot.htm">"M. Memo"</a>. <i>J Vocabulary</i>. J Software<span class="reference-accessdate">. Retrieved <span class="nowrap">28 October</span> 2011</span>.</cite></span>
</li>
<li id="cite_note-6"><span class="mw-cite-backlink"><b><a href="#cite_ref-6">^</a></b></span> <span class="reference-text"><cite id="CITEREFDelisi1974" class="citation cs2">Delisi, Charles (July 1974), "Cooperative phenomena in homopolymers: An alternative formulation of the partition function", <i>Biopolymers</i>, <b>13</b> (7): <span class="nowrap">1511–</span>1512, <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1002%2Fbip.1974.360130719">10.1002/bip.1974.360130719</a></cite></span>
</li>
<li id="cite_note-7"><span class="mw-cite-backlink"><b><a href="#cite_ref-7">^</a></b></span> <span class="reference-text"><cite id="CITEREFGurskiĭZasedatelev1978" class="citation cs2">Gurskiĭ, G. V.; Zasedatelev, A. S. (September 1978), "Precise relationships for calculating the binding of regulatory proteins and other lattice ligands in double-stranded polynucleotides", <i>Biofizika</i>, <b>23</b> (5): <span class="nowrap">932–</span>946, <a href="PMID_(identifier)" class="mw-redirect" title="PMID (identifier)">PMID</a>&nbsp;<a rel="nofollow" class="external text" href="https://pubmed.ncbi.nlm.nih.gov/698271">698271</a></cite></span>
</li>
<li id="cite_note-sniedovich_06-8"><span class="mw-cite-backlink"><b><a href="#cite_ref-sniedovich_06_8-0">^</a></b></span> <span class="reference-text"><cite id="CITEREFSniedovich2006" class="citation cs2">Sniedovich, M. (2006), <a rel="nofollow" class="external text" href="http://matwbn.icm.edu.pl/ksiazki/cc/cc35/cc3536.pdf">"Dijkstra's algorithm revisited: the dynamic programming connexion"</a> <span class="cs1-format">(PDF)</span>, <i>Journal of Control and Cybernetics</i>, <b>35</b> (3): <span class="nowrap">599–</span>620.</cite> <a rel="nofollow" class="external text" href="http://www.ifors.ms.unimelb.edu.au/tutorial/dijkstra_new/index.html">Online version of the paper with interactive computational modules.</a></span>
</li>
<li id="cite_note-denardo_03-9"><span class="mw-cite-backlink"><b><a href="#cite_ref-denardo_03_9-0">^</a></b></span> <span class="reference-text"><cite id="CITEREFDenardo2003" class="citation cs2">Denardo, E.V. (2003), <i>Dynamic Programming: Models and Applications</i>, Mineola, NY: <a href="Dover_Publications" title="Dover Publications">Dover Publications</a>, <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>978-0-486-42810-9</bdi></cite></span>
</li>
<li id="cite_note-sniedovich_10-10"><span class="mw-cite-backlink"><b><a href="#cite_ref-sniedovich_10_10-0">^</a></b></span> <span class="reference-text"><cite id="CITEREFSniedovich2010" class="citation cs2">Sniedovich, M. (2010), <i>Dynamic Programming: Foundations and Principles</i>, <a href="Taylor_%26_Francis" title="Taylor &amp; Francis">Taylor &amp; Francis</a>, <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>978-0-8247-4099-3</bdi></cite></span>
</li>
<li id="cite_note-11"><span class="mw-cite-backlink"><b><a href="#cite_ref-11">^</a></b></span> <span class="reference-text"><cite id="CITEREFDijkstra1959" class="citation journal cs1"><a href="Edsger_W._Dijkstra" title="Edsger W. Dijkstra">Dijkstra, E. W.</a> (December 1959). "A note on two problems in connexion with graphs". <i>Numerische Mathematik</i>. <b>1</b> (1): <span class="nowrap">269–</span>271. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1007%2FBF01386390">10.1007/BF01386390</a>.</cite></span>
</li>
<li id="cite_note-Eddy-12"><span class="mw-cite-backlink">^ <a href="#cite_ref-Eddy_12-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-Eddy_12-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text"><cite id="CITEREFEddy2004" class="citation journal cs1"><a href="Sean_Eddy" title="Sean Eddy">Eddy, S. R.</a> (2004). "What is Dynamic Programming?". <i>Nature Biotechnology</i>. <b>22</b> (7): <span class="nowrap">909–</span>910. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1038%2Fnbt0704-909">10.1038/nbt0704-909</a>. <a href="PMID_(identifier)" class="mw-redirect" title="PMID (identifier)">PMID</a>&nbsp;<a rel="nofollow" class="external text" href="https://pubmed.ncbi.nlm.nih.gov/15229554">15229554</a>. <a href="S2CID_(identifier)" class="mw-redirect" title="S2CID (identifier)">S2CID</a>&nbsp;<a rel="nofollow" class="external text" href="https://api.semanticscholar.org/CorpusID:5352062">5352062</a>.</cite></span>
</li>
<li id="cite_note-13"><span class="mw-cite-backlink"><b><a href="#cite_ref-13">^</a></b></span> <span class="reference-text"><cite id="CITEREFMoshe_Sniedovich2002" class="citation cs2">Moshe Sniedovich (2002), "OR/MS Games: 2. The Towers of Hanoi Problem", <i>INFORMS Transactions on Education</i>, <b>3</b> (1): <span class="nowrap">34–</span>51, <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://doi.org/10.1287%2Fited.3.1.45">10.1287/ited.3.1.45</a></span>.</cite></span>
</li>
<li id="cite_note-14"><span class="mw-cite-backlink"><b><a href="#cite_ref-14">^</a></b></span> <span class="reference-text">Konhauser J.D.E., Velleman, D., and Wagon, S. (1996). <a rel="nofollow" class="external text" href="https://books.google.com/books?id=ElSi5V5uS2MC">Which way did the Bicycle Go?</a> Dolciani Mathematical Expositions – No 18. <a href="The_Mathematical_Association_of_America" class="mw-redirect" title="The Mathematical Association of America">The Mathematical Association of America</a>.</span>
</li>
<li id="cite_note-sniedovich_03-15"><span class="mw-cite-backlink"><b><a href="#cite_ref-sniedovich_03_15-0">^</a></b></span> <span class="reference-text"><cite id="CITEREFSniedovich2003" class="citation journal cs1">Sniedovich, Moshe (2003). <a rel="nofollow" class="external text" href="https://doi.org/10.1287%2Fited.4.1.48">"OR/MS Games: 4. The Joy of Egg-Dropping in Braunschweig and Hong Kong"</a>. <i>INFORMS Transactions on Education</i>. <b>4</b> (1): <span class="nowrap">48–</span>64. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://doi.org/10.1287%2Fited.4.1.48">10.1287/ited.4.1.48</a></span>.</cite></span>
</li>
<li id="cite_note-16"><span class="mw-cite-backlink"><b><a href="#cite_ref-16">^</a></b></span> <span class="reference-text"><cite id="CITEREFDean_Connable_Wills" class="citation cs2">Dean Connable Wills, <a rel="nofollow" class="external text" href="https://ir.library.oregonstate.edu/xmlui/handle/1957/11929?show=full"><i>Connections between combinatorics of permutations and algorithms and geometry</i></a></cite></span>
</li>
<li id="cite_note-17"><span class="mw-cite-backlink"><b><a href="#cite_ref-17">^</a></b></span> <span class="reference-text">Stuart Dreyfus. <a rel="nofollow" class="external text" href="https://web.archive.org/web/20050110161049/http://www.wu-wien.ac.at/usr/h99c/h9951826/bellman_dynprog.pdf">"Richard Bellman on the birth of Dynamical Programming"</a>.</span>
</li>
<li id="cite_note-18"><span class="mw-cite-backlink"><b><a href="#cite_ref-18">^</a></b></span> <span class="reference-text"><cite id="CITEREFNocedalWright2006" class="citation book cs1">Nocedal, J.; Wright, S. J. (2006). <span class="id-lock-limited" title="Free access subject to limited trial, subscription normally required"><a rel="nofollow" class="external text" href="https://archive.org/details/numericaloptimiz00noce_639"><i>Numerical Optimization</i></a></span>. Springer. p.&nbsp;<a rel="nofollow" class="external text" href="https://archive.org/details/numericaloptimiz00noce_639/page/n21">9</a>. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>9780387303031</bdi>.</cite></span>
</li>
<li id="cite_note-19"><span class="mw-cite-backlink"><b><a href="#cite_ref-19">^</a></b></span> <span class="reference-text"><cite id="CITEREFRussellNorvig2009" class="citation book cs1">Russell, S.; Norvig, P. (2009). <i>Artificial Intelligence: A Modern Approach</i> (3rd&nbsp;ed.). Prentice Hall. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>978-0-13-207148-2</bdi>.</cite></span>
</li>
<li id="cite_note-20"><span class="mw-cite-backlink"><b><a href="#cite_ref-20">^</a></b></span> <span class="reference-text"><cite id="CITEREFKushner2004" class="citation web cs1"><a href="Harold_J._Kushner" title="Harold J. Kushner">Kushner, Harold J.</a> (2004-07-01). <a rel="nofollow" class="external text" href="https://web.archive.org/web/20141019015133/http://a2c2.org/awards/richard-e-bellman-control-heritage-award/2004-00-00t000000/harold-j-kushner">"Richard E. Bellman Control Heritage Award"</a>. Archived from <a rel="nofollow" class="external text" href="http://a2c2.org/awards/richard-e-bellman-control-heritage-award-0">the original</a> on 2014-10-19.</cite></span>
</li>
</ol></div></div>
<div class="mw-heading mw-heading2"><h2 id="Further_reading">Further reading</h2></div>
<ul><li><cite id="CITEREFAddaCooper2003" class="citation cs2">Adda, Jerome; Cooper, Russell (2003), <a rel="nofollow" class="external text" href="https://mitpress.mit.edu/books/dynamic-economics"><i>Dynamic Economics</i></a>, MIT Press, <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>9780262012010</bdi></cite>. An accessible introduction to dynamic programming in economics. <a rel="nofollow" class="external text" href="https://sites.google.com/site/coopereconomics/matlab-programs">MATLAB code for the book</a> <a rel="nofollow" class="external text" href="https://web.archive.org/web/20201009085820/https://sites.google.com/site/coopereconomics/matlab-programs">Archived</a> 2020-10-09 at the <a href="Wayback_Machine" title="Wayback Machine">Wayback Machine</a>.</li>
<li><cite id="CITEREFBellman1954" class="citation cs2"><a href="Richard_Bellman" class="mw-redirect" title="Richard Bellman">Bellman, Richard</a> (1954), "The theory of dynamic programming", <i><a href="Bulletin_of_the_American_Mathematical_Society" title="Bulletin of the American Mathematical Society">Bulletin of the American Mathematical Society</a></i>, <b>60</b> (6): <span class="nowrap">503–</span>516, <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://doi.org/10.1090%2FS0002-9904-1954-09848-8">10.1090/S0002-9904-1954-09848-8</a></span>, <a href="MR_(identifier)" class="mw-redirect" title="MR (identifier)">MR</a>&nbsp;<a rel="nofollow" class="external text" href="https://mathscinet.ams.org/mathscinet-getitem?mr=0067459">0067459</a></cite>. Includes an extensive bibliography of the literature in the area, up to the year 1954.</li>
<li><cite id="CITEREFBellman1957" class="citation cs2"><a href="Richard_Bellman" class="mw-redirect" title="Richard Bellman">Bellman, Richard</a> (1957), <i>Dynamic Programming</i>, Princeton University Press</cite>. Dover paperback edition (2003), <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>0-486-42809-5</bdi>.</li>
<li><cite id="CITEREFCormenLeisersonRivestStein2001" class="citation cs2"><a href="Thomas_H._Cormen" title="Thomas H. Cormen">Cormen, Thomas H.</a>; <a href="Charles_E._Leiserson" title="Charles E. Leiserson">Leiserson, Charles E.</a>; <a href="Ronald_L._Rivest" class="mw-redirect" title="Ronald L. Rivest">Rivest, Ronald L.</a>; <a href="Clifford_Stein" title="Clifford Stein">Stein, Clifford</a> (2001), <a href="Introduction_to_Algorithms" title="Introduction to Algorithms"><i>Introduction to Algorithms</i></a> (2nd&nbsp;ed.), MIT Press &amp; McGraw–Hill, <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>978-0-262-03293-3</bdi></cite>. Especially pp.&nbsp;323–69.</li>
<li><cite id="CITEREFDreyfusLaw1977" class="citation cs2">Dreyfus, Stuart E.; Law, Averill M. (1977), <i>The Art and Theory of Dynamic Programming</i>, Academic Press, <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>978-0-12-221860-6</bdi></cite>.</li>
<li><cite id="CITEREFGiegerichMeyerSteffen2004" class="citation cs2">Giegerich, R.; Meyer, C.; Steffen, P. (2004), <a rel="nofollow" class="external text" href="http://bibiserv.techfak.uni-bielefeld.de/adp/ps/GIE-MEY-STE-2004.pdf">"A Discipline of Dynamic Programming over Sequence Data"</a> <span class="cs1-format">(PDF)</span>, <i>Science of Computer Programming</i>, <b>51</b> (3): <span class="nowrap">215–</span>263, <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://doi.org/10.1016%2Fj.scico.2003.12.005">10.1016/j.scico.2003.12.005</a></span></cite>.</li>
<li><cite id="CITEREFMeyn2007" class="citation cs2">Meyn, Sean (2007), <a rel="nofollow" class="external text" href="https://web.archive.org/web/20100619011046/https://netfiles.uiuc.edu/meyn/www/spm_files/CTCN/CTCN.html"><i>Control Techniques for Complex Networks</i></a>, Cambridge University Press, <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>978-0-521-88441-9</bdi>, archived from <a rel="nofollow" class="external text" href="https://netfiles.uiuc.edu/meyn/www/spm_files/CTCN/CTCN.html">the original</a> on 2010-06-19</cite>.</li>
<li><cite id="CITEREFSritharan1991" class="citation journal cs1">Sritharan, S. S. (1991). "Dynamic Programming of the Navier-Stokes Equations". <i>Systems and Control Letters</i>. <b>16</b> (4): <span class="nowrap">299–</span>307. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1016%2F0167-6911%2891%2990020-f">10.1016/0167-6911(91)90020-f</a>.</cite></li>
<li><cite id="CITEREFStokeyLucasPrescott1989" class="citation cs2"><a href="Nancy_Stokey" title="Nancy Stokey">Stokey, Nancy</a>; <a href="Robert_E._Lucas" class="mw-redirect" title="Robert E. Lucas">Lucas, Robert E.</a>; <a href="Edward_Prescott" class="mw-redirect" title="Edward Prescott">Prescott, Edward</a> (1989), <i>Recursive Methods in Economic Dynamics</i>, Harvard Univ. Press, <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>978-0-674-75096-8</bdi></cite>.</li></ul>
<div class="mw-heading mw-heading2"><h2 id="External_links">External links</h2></div>
<ul><li>King, Ian, 2002 (1987), "<a rel="nofollow" class="external text" href="https://researchspace.auckland.ac.nz/bitstream/handle/2292/190/230.pdf">A Simple Introduction to Dynamic Programming in Macroeconomic Models.</a>" An introduction to dynamic programming as an important tool in economic theory.</li></ul>
<p><br>
</p><p><br>
</p>
<div class="navbox-styles"><style data-mw-deduplicate="TemplateStyles:r1129693374">
/* start https://en.wikipedia.org/ */


.mw-parser-output .hlist dl,.mw-parser-output .hlist ol,.mw-parser-output .hlist ul{margin:0;padding:0}.mw-parser-output .hlist dd,.mw-parser-output .hlist dt,.mw-parser-output .hlist li{margin:0;display:inline}.mw-parser-output .hlist.inline,.mw-parser-output .hlist.inline dl,.mw-parser-output .hlist.inline ol,.mw-parser-output .hlist.inline ul,.mw-parser-output .hlist dl dl,.mw-parser-output .hlist dl ol,.mw-parser-output .hlist dl ul,.mw-parser-output .hlist ol dl,.mw-parser-output .hlist ol ol,.mw-parser-output .hlist ol ul,.mw-parser-output .hlist ul dl,.mw-parser-output .hlist ul ol,.mw-parser-output .hlist ul ul{display:inline}.mw-parser-output .hlist .mw-empty-li{display:none}.mw-parser-output .hlist dt::after{content:": "}.mw-parser-output .hlist dd::after,.mw-parser-output .hlist li::after{content:" · ";font-weight:bold}.mw-parser-output .hlist dd:last-child::after,.mw-parser-output .hlist dt:last-child::after,.mw-parser-output .hlist li:last-child::after{content:none}.mw-parser-output .hlist dd dd:first-child::before,.mw-parser-output .hlist dd dt:first-child::before,.mw-parser-output .hlist dd li:first-child::before,.mw-parser-output .hlist dt dd:first-child::before,.mw-parser-output .hlist dt dt:first-child::before,.mw-parser-output .hlist dt li:first-child::before,.mw-parser-output .hlist li dd:first-child::before,.mw-parser-output .hlist li dt:first-child::before,.mw-parser-output .hlist li li:first-child::before{content:" (";font-weight:normal}.mw-parser-output .hlist dd dd:last-child::after,.mw-parser-output .hlist dd dt:last-child::after,.mw-parser-output .hlist dd li:last-child::after,.mw-parser-output .hlist dt dd:last-child::after,.mw-parser-output .hlist dt dt:last-child::after,.mw-parser-output .hlist dt li:last-child::after,.mw-parser-output .hlist li dd:last-child::after,.mw-parser-output .hlist li dt:last-child::after,.mw-parser-output .hlist li li:last-child::after{content:")";font-weight:normal}.mw-parser-output .hlist ol{counter-reset:listitem}.mw-parser-output .hlist ol>li{counter-increment:listitem}.mw-parser-output .hlist ol>li::before{content:" "counter(listitem)"\a0 "}.mw-parser-output .hlist dd ol>li:first-child::before,.mw-parser-output .hlist dt ol>li:first-child::before,.mw-parser-output .hlist li ol>li:first-child::before{content:" ("counter(listitem)"\a0 "}


/* end https://en.wikipedia.org/ */
</style><style data-mw-deduplicate="TemplateStyles:r1236075235">
/* start https://en.wikipedia.org/ */


.mw-parser-output .navbox{box-sizing:border-box;border:1px solid #a2a9b1;width:100%;clear:both;font-size:88%;text-align:center;padding:1px;margin:1em auto 0}.mw-parser-output .navbox .navbox{margin-top:0}.mw-parser-output .navbox+.navbox,.mw-parser-output .navbox+.navbox-styles+.navbox{margin-top:-1px}.mw-parser-output .navbox-inner,.mw-parser-output .navbox-subgroup{width:100%}.mw-parser-output .navbox-group,.mw-parser-output .navbox-title,.mw-parser-output .navbox-abovebelow{padding:0.25em 1em;line-height:1.5em;text-align:center}.mw-parser-output .navbox-group{white-space:nowrap;text-align:right}.mw-parser-output .navbox,.mw-parser-output .navbox-subgroup{background-color:#fdfdfd}.mw-parser-output .navbox-list{line-height:1.5em;border-color:#fdfdfd}.mw-parser-output .navbox-list-with-group{text-align:left;border-left-width:2px;border-left-style:solid}.mw-parser-output tr+tr>.navbox-abovebelow,.mw-parser-output tr+tr>.navbox-group,.mw-parser-output tr+tr>.navbox-image,.mw-parser-output tr+tr>.navbox-list{border-top:2px solid #fdfdfd}.mw-parser-output .navbox-title{background-color:#ccf}.mw-parser-output .navbox-abovebelow,.mw-parser-output .navbox-group,.mw-parser-output .navbox-subgroup .navbox-title{background-color:#ddf}.mw-parser-output .navbox-subgroup .navbox-group,.mw-parser-output .navbox-subgroup .navbox-abovebelow{background-color:#e6e6ff}.mw-parser-output .navbox-even{background-color:#f7f7f7}.mw-parser-output .navbox-odd{background-color:transparent}.mw-parser-output .navbox .hlist td dl,.mw-parser-output .navbox .hlist td ol,.mw-parser-output .navbox .hlist td ul,.mw-parser-output .navbox td.hlist dl,.mw-parser-output .navbox td.hlist ol,.mw-parser-output .navbox td.hlist ul{padding:0.125em 0}.mw-parser-output .navbox .navbar{display:block;font-size:100%}.mw-parser-output .navbox-title .navbar{float:left;text-align:left;margin-right:0.5em}body.skin--responsive .mw-parser-output .navbox-image img{max-width:none!important}@media print{body.ns-0 .mw-parser-output .navbox{display:none!important}}


/* end https://en.wikipedia.org/ */
</style></div><div role="navigation" class="navbox" aria-labelledby="Optimization:_Algorithms,_methods,_and_heuristics381" style="padding:3px"><table class="nowraplinks hlist mw-collapsible expanded navbox-inner" style="border-spacing:0;background:transparent;color:inherit"><tbody><tr><th scope="col" class="navbox-title" colspan="3"><style data-mw-deduplicate="TemplateStyles:r1239400231">
/* start https://en.wikipedia.org/ */


.mw-parser-output .navbar{display:inline;font-size:88%;font-weight:normal}.mw-parser-output .navbar-collapse{float:left;text-align:left}.mw-parser-output .navbar-boxtext{word-spacing:0}.mw-parser-output .navbar ul{display:inline-block;white-space:nowrap;line-height:inherit}.mw-parser-output .navbar-brackets::before{margin-right:-0.125em;content:"[ "}.mw-parser-output .navbar-brackets::after{margin-left:-0.125em;content:" ]"}.mw-parser-output .navbar li{word-spacing:-0.125em}.mw-parser-output .navbar a>span,.mw-parser-output .navbar a>abbr{text-decoration:inherit}.mw-parser-output .navbar-mini abbr{font-variant:small-caps;border-bottom:none;text-decoration:none;cursor:inherit}.mw-parser-output .navbar-ct-full{font-size:114%;margin:0 7em}.mw-parser-output .navbar-ct-mini{font-size:114%;margin:0 4em}html.skin-theme-clientpref-night .mw-parser-output .navbar li a abbr{color:var(--color-base)!important}@media(prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .navbar li a abbr{color:var(--color-base)!important}}@media print{.mw-parser-output .navbar{display:none!important}}


/* end https://en.wikipedia.org/ */
</style><div id="Optimization:_Algorithms,_methods,_and_heuristics381" style="font-size:114%;margin:0 4em"><a href="Mathematical_optimization" title="Mathematical optimization">Optimization</a>: <a href="Optimization_algorithm" class="mw-redirect" title="Optimization algorithm">Algorithms</a>, <a href="Iterative_method" title="Iterative method">methods</a>, and <a href="Heuristic_algorithm" class="mw-redirect" title="Heuristic algorithm">heuristics</a></div></th></tr><tr><td colspan="2" class="navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em"></div><table class="nowraplinks mw-collapsible mw-collapsed navbox-subgroup" style="border-spacing:0"><tbody><tr><th scope="col" class="navbox-title" colspan="2"><div id="Unconstrained_nonlinear381" style="font-size:114%;margin:0 4em"><a href="Nonlinear_programming" title="Nonlinear programming">Unconstrained nonlinear</a></div></th></tr><tr><td colspan="2" class="navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em"></div><table class="nowraplinks navbox-subgroup" style="border-spacing:0"><tbody><tr><th scope="row" class="navbox-group" style="width:1%"><a href="Function_(mathematics)" title="Function (mathematics)">Functions</a></th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Golden-section_search" title="Golden-section search">Golden-section search</a></li>
<li><a href="Powell's_method" title="Powell's method">Powell's method</a></li>
<li><a href="Line_search" title="Line search">Line search</a></li>
<li><a href="Nelder%E2%80%93Mead_method" title="Nelder–Mead method">Nelder–Mead method</a></li>
<li><a href="Successive_parabolic_interpolation" title="Successive parabolic interpolation">Successive parabolic interpolation</a></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="Gradient" title="Gradient">Gradients</a></th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em"></div><table class="nowraplinks navbox-subgroup" style="border-spacing:0"><tbody><tr><th scope="row" class="navbox-group" style="width:1%"><a href="Local_convergence" title="Local convergence">Convergence</a></th><td class="navbox-list-with-group navbox-list navbox-even" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Trust_region" title="Trust region">Trust region</a></li>
<li><a href="Wolfe_conditions" title="Wolfe conditions">Wolfe conditions</a></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="Quasi-Newton_method" title="Quasi-Newton method">Quasi–Newton</a></th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Berndt%E2%80%93Hall%E2%80%93Hall%E2%80%93Hausman_algorithm" title="Berndt–Hall–Hall–Hausman algorithm">Berndt–Hall–Hall–Hausman</a></li>
<li><a href="Broyden%E2%80%93Fletcher%E2%80%93Goldfarb%E2%80%93Shanno_algorithm" title="Broyden–Fletcher–Goldfarb–Shanno algorithm">Broyden–Fletcher–Goldfarb–Shanno</a> and <a href="Limited-memory_BFGS" title="Limited-memory BFGS">L-BFGS</a></li>
<li><a href="Davidon%E2%80%93Fletcher%E2%80%93Powell_formula" title="Davidon–Fletcher–Powell formula">Davidon–Fletcher–Powell</a></li>
<li><a href="Symmetric_rank-one" title="Symmetric rank-one">Symmetric rank-one (SR1)</a></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="Iterative_method" title="Iterative method">Other methods</a></th><td class="navbox-list-with-group navbox-list navbox-even" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Nonlinear_conjugate_gradient_method" title="Nonlinear conjugate gradient method">Conjugate gradient</a></li>
<li><a href="Gauss%E2%80%93Newton_algorithm" title="Gauss–Newton algorithm">Gauss–Newton</a></li>
<li><a href="Gradient_descent" title="Gradient descent">Gradient</a></li>
<li><a href="Mirror_descent" title="Mirror descent">Mirror</a></li>
<li><a href="Levenberg%E2%80%93Marquardt_algorithm" title="Levenberg–Marquardt algorithm">Levenberg–Marquardt</a></li>
<li><a href="Powell's_dog_leg_method" title="Powell's dog leg method">Powell's dog leg method</a></li>
<li><a href="Truncated_Newton_method" title="Truncated Newton method">Truncated Newton</a></li></ul>
</div></td></tr></tbody></table><div></div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="Hessian_matrix" title="Hessian matrix">Hessians</a></th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Newton's_method_in_optimization" title="Newton's method in optimization">Newton's method</a></li></ul>
</div></td></tr></tbody></table><div></div></td></tr></tbody></table><div></div></td><td class="noviewer navbox-image" rowspan="5" style="width:1px;padding:0 0 0 2px"><div></div></td></tr><tr><td colspan="2" class="navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em"></div><table class="nowraplinks mw-collapsible mw-collapsed navbox-subgroup" style="border-spacing:0"><tbody><tr><th scope="col" class="navbox-title" colspan="2"><div id="Constrained_nonlinear381" style="font-size:114%;margin:0 4em"><a href="Nonlinear_programming" title="Nonlinear programming">Constrained nonlinear</a></div></th></tr><tr><td colspan="2" class="navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em"></div><table class="nowraplinks navbox-subgroup" style="border-spacing:0"><tbody><tr><th scope="row" class="navbox-group" style="width:1%">General</th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Barrier_function" title="Barrier function">Barrier methods</a></li>
<li><a href="Penalty_method" title="Penalty method">Penalty methods</a></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">Differentiable</th><td class="navbox-list-with-group navbox-list navbox-even" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Augmented_Lagrangian_method" title="Augmented Lagrangian method">Augmented Lagrangian methods</a></li>
<li><a href="Sequential_quadratic_programming" title="Sequential quadratic programming">Sequential quadratic programming</a></li>
<li><a href="Successive_linear_programming" title="Successive linear programming">Successive linear programming</a></li></ul>
</div></td></tr></tbody></table><div></div></td></tr></tbody></table><div></div></td></tr><tr><td colspan="2" class="navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em"></div><table class="nowraplinks mw-collapsible mw-collapsed navbox-subgroup" style="border-spacing:0"><tbody><tr><th scope="col" class="navbox-title" colspan="2"><div id="Convex_optimization381" style="font-size:114%;margin:0 4em"><a href="Convex_optimization" title="Convex optimization">Convex optimization</a></div></th></tr><tr><td colspan="2" class="navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em"></div><table class="nowraplinks navbox-subgroup" style="border-spacing:0"><tbody><tr><th scope="row" class="navbox-group" style="width:1%"><a href="Convex_minimization" class="mw-redirect" title="Convex minimization">Convex<br> minimization</a></th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Cutting-plane_method" title="Cutting-plane method">Cutting-plane method</a></li>
<li><a href="Frank%E2%80%93Wolfe_algorithm" title="Frank–Wolfe algorithm">Reduced gradient (Frank–Wolfe)</a></li>
<li><a href="Subgradient_method" title="Subgradient method">Subgradient method</a></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="Linear_programming" title="Linear programming">Linear</a> and<br><a href="Quadratic_programming" title="Quadratic programming">quadratic</a></th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em"></div><table class="nowraplinks navbox-subgroup" style="border-spacing:0"><tbody><tr><th scope="row" class="navbox-group" style="width:1%"><a href="Linear_programming#Interior_point" title="Linear programming">Interior point</a></th><td class="navbox-list-with-group navbox-list navbox-even" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Affine_scaling" title="Affine scaling">Affine scaling</a></li>
<li><a href="Ellipsoid_method" title="Ellipsoid method">Ellipsoid algorithm of Khachiyan</a></li>
<li><a href="Karmarkar's_algorithm" title="Karmarkar's algorithm">Projective algorithm of Karmarkar</a></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="Matroid" title="Matroid">Basis-</a><a href="Exchange_algorithm" class="mw-redirect" title="Exchange algorithm">exchange</a></th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Simplex_algorithm" title="Simplex algorithm">Simplex algorithm of Dantzig</a></li>
<li><a href="Revised_simplex_method" title="Revised simplex method">Revised simplex algorithm</a></li>
<li><a href="Criss-cross_algorithm" title="Criss-cross algorithm">Criss-cross algorithm</a></li>
<li><a href="Lemke's_algorithm" title="Lemke's algorithm">Principal pivoting algorithm of Lemke</a></li>
<li><a href="Active-set_method" title="Active-set method">Active-set method</a></li></ul>
</div></td></tr></tbody></table><div></div></td></tr></tbody></table><div></div></td></tr></tbody></table><div></div></td></tr><tr><td colspan="2" class="navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em"></div><table class="nowraplinks mw-collapsible uncollapsed navbox-subgroup" style="border-spacing:0"><tbody><tr><th scope="col" class="navbox-title" colspan="2"><div id="Combinatorial381" style="font-size:114%;margin:0 4em"><a href="Combinatorial_optimization" title="Combinatorial optimization">Combinatorial</a></div></th></tr><tr><td colspan="2" class="navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em"></div><table class="nowraplinks navbox-subgroup" style="border-spacing:0"><tbody><tr><th scope="row" class="navbox-group" style="width:1%">Paradigms</th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Approximation_algorithm" title="Approximation algorithm">Approximation algorithm</a></li>

<li><a href="Greedy_algorithm" title="Greedy algorithm">Greedy algorithm</a></li>
<li><a href="Integer_programming" title="Integer programming">Integer programming</a>
<ul><li><a href="Branch_and_bound" title="Branch and bound">Branch and bound</a>/<a href="Branch_and_cut" title="Branch and cut">cut</a></li></ul></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="Graph_algorithm" class="mw-redirect" title="Graph algorithm">Graph<br> algorithms</a></th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em"></div><table class="nowraplinks navbox-subgroup" style="border-spacing:0"><tbody><tr><th id="Minimum_spanning_tree52" scope="row" class="navbox-group" style="width:1%"><a href="Minimum_spanning_tree" title="Minimum spanning tree">Minimum<br> spanning tree</a></th><td class="navbox-list-with-group navbox-list navbox-even" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Bor%C5%AFvka's_algorithm" title="Borůvka's algorithm">Borůvka</a></li>
<li><a href="Prim's_algorithm" title="Prim's algorithm">Prim</a></li>
<li><a href="Kruskal's_algorithm" title="Kruskal's algorithm">Kruskal</a></li></ul>
</div></td></tr></tbody></table><div>
</div><table class="nowraplinks navbox-subgroup" style="border-spacing:0"><tbody><tr><th id="Shortest_path39" scope="row" class="navbox-group" style="width:1%"><a href="Shortest_path_problem" title="Shortest path problem">Shortest path</a></th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Bellman%E2%80%93Ford_algorithm" title="Bellman–Ford algorithm">Bellman–Ford</a>
<ul><li><a href="Shortest_Path_Faster_Algorithm" class="mw-redirect" title="Shortest Path Faster Algorithm">SPFA</a></li></ul></li>
<li><a href="Dijkstra's_algorithm" title="Dijkstra's algorithm">Dijkstra</a></li>
<li><a href="Floyd%E2%80%93Warshall_algorithm" title="Floyd–Warshall algorithm">Floyd–Warshall</a></li></ul>
</div></td></tr></tbody></table><div></div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="Flow_network" title="Flow network">Network flows</a></th><td class="navbox-list-with-group navbox-list navbox-even" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Dinic's_algorithm" title="Dinic's algorithm">Dinic</a></li>
<li><a href="Edmonds%E2%80%93Karp_algorithm" title="Edmonds–Karp algorithm">Edmonds–Karp</a></li>
<li><a href="Ford%E2%80%93Fulkerson_algorithm" title="Ford–Fulkerson algorithm">Ford–Fulkerson</a></li>
<li><a href="Push%E2%80%93relabel_maximum_flow_algorithm" title="Push–relabel maximum flow algorithm">Push–relabel maximum flow</a></li></ul>
</div></td></tr></tbody></table><div></div></td></tr></tbody></table><div></div></td></tr><tr><td colspan="2" class="navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em"></div><table class="nowraplinks mw-collapsible mw-collapsed navbox-subgroup" style="border-spacing:0"><tbody><tr><th scope="col" class="navbox-title" colspan="2"><div id="Metaheuristics381" style="font-size:114%;margin:0 4em"><a href="Metaheuristic" title="Metaheuristic">Metaheuristics</a></div></th></tr><tr><td colspan="2" class="navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Evolutionary_algorithm" title="Evolutionary algorithm">Evolutionary algorithm</a></li>
<li><a href="Hill_climbing" title="Hill climbing">Hill climbing</a></li>
<li><a href="Local_search_(optimization)" title="Local search (optimization)">Local search</a></li>
<li><a href="Parallel_metaheuristic" title="Parallel metaheuristic">Parallel metaheuristics</a></li>
<li><a href="Simulated_annealing" title="Simulated annealing">Simulated annealing</a></li>
<li><a href="Spiral_optimization_algorithm" title="Spiral optimization algorithm">Spiral optimization algorithm</a></li>
<li><a href="Tabu_search" title="Tabu search">Tabu search</a></li></ul>
</div></td></tr></tbody></table><div></div></td></tr><tr><td class="navbox-abovebelow" colspan="3"><div>
<ul><li><a href="Comparison_of_optimization_software" title="Comparison of optimization software">Software</a></li></ul>
</div></td></tr></tbody></table></div>
<div class="navbox-styles"></div><div role="navigation" class="navbox" aria-labelledby="Parsing_algorithms116" style="padding:3px"><table class="nowraplinks mw-collapsible autocollapse navbox-inner" style="border-spacing:0;background:transparent;color:inherit"><tbody><tr><th scope="col" class="navbox-title" colspan="2"><div id="Parsing_algorithms116" style="font-size:114%;margin:0 4em"><a href="Parsing" title="Parsing">Parsing algorithms</a></div></th></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="Top-down_parsing" title="Top-down parsing">Top-down</a></th><td class="navbox-list-with-group navbox-list navbox-odd hlist" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Earley_parser" title="Earley parser">Earley</a></li>
<li><a href="LL_parser" title="LL parser">LL</a></li>
<li><a href="Recursive_descent_parser" title="Recursive descent parser">Recursive descent</a>
<ul><li><a href="Tail_recursive_parser" title="Tail recursive parser">Tail recursive</a></li></ul></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="Bottom-up_parsing" title="Bottom-up parsing">Bottom-up</a></th><td class="navbox-list-with-group navbox-list navbox-even hlist" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li>Precedence
<ul><li><a href="Simple_precedence_parser" title="Simple precedence parser">Simple</a></li>
<li><a href="Operator-precedence_parser" title="Operator-precedence parser">Operator</a>
<ul><li><a href="Shunting_yard_algorithm" title="Shunting yard algorithm">Shunting-yard</a></li></ul></li></ul></li>
<li><a href="LR_parser" title="LR parser">LR</a>
<ul><li><a href="Simple_LR_parser" title="Simple LR parser">Simple</a></li>
<li><a href="LALR_parser" title="LALR parser">Look-ahead</a></li>
<li><a href="Canonical_LR_parser" title="Canonical LR parser">Canonical</a></li>
<li><a href="GLR_parser" title="GLR parser">Generalized</a></li></ul></li>
<li><a href="CYK_algorithm" title="CYK algorithm">CYK</a></li>
<li><a href="Recursive_ascent_parser" title="Recursive ascent parser">Recursive ascent</a></li>
<li><a href="Shift-reduce_parser" title="Shift-reduce parser">Shift-reduce</a></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">Mixed, other</th><td class="navbox-list-with-group navbox-list navbox-odd hlist" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Parser_combinator" title="Parser combinator">Combinator</a></li>
<li><a href="Chart_parser" title="Chart parser">Chart</a>
<ul><li><a href="Left_corner_parser" title="Left corner parser">Left corner</a></li></ul></li>
<li>Statistical</li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">Related topics</th><td class="navbox-list-with-group navbox-list navbox-even hlist" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Parsing_expression_grammar" title="Parsing expression grammar">PEG</a></li>
<li><a href="Definite_clause_grammar" title="Definite clause grammar">Definite clause grammar</a></li>
<li><a href="Deterministic_parsing" title="Deterministic parsing">Deterministic parsing</a></li>

<li><a href="Memoization" title="Memoization">Memoization</a></li>
<li><a href="Compiler-compiler" title="Compiler-compiler">Parser generator</a>
<ul><li><a href="LALR_parser_generator" title="LALR parser generator">LALR</a></li></ul></li>
<li><a href="Parse_tree" title="Parse tree">Parse tree</a></li>
<li><a href="Abstract_syntax_tree" title="Abstract syntax tree">AST</a></li>
<li><a href="Scannerless_parsing" title="Scannerless parsing">Scannerless parsing</a></li>
<li><a href="History_of_compiler_construction" title="History of compiler construction">History of compiler construction</a></li>
<li><a href="Comparison_of_parser_generators" title="Comparison of parser generators">Comparison of parser generators</a></li>
<li><a href="Operator-precedence_grammar" title="Operator-precedence grammar">Operator-precedence grammar</a></li></ul>
</div></td></tr></tbody></table></div>
<div class="navbox-styles"></div><div role="navigation" class="navbox" aria-labelledby="Data_structures_and_algorithms145" style="padding:3px"><table class="nowraplinks hlist mw-collapsible autocollapse navbox-inner" style="border-spacing:0;background:transparent;color:inherit"><tbody><tr><th scope="col" class="navbox-title" colspan="2"><div id="Data_structures_and_algorithms145" style="font-size:114%;margin:0 4em"><a href="Data_structure" title="Data structure">Data structures</a> and <a href="Algorithm" title="Algorithm">algorithms</a></div></th></tr><tr><th scope="row" class="navbox-group" style="width:1%">Data structures</th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Array_(data_structure)" title="Array (data structure)">Array</a></li>
<li><a href="Associative_array" title="Associative array">Associative array</a></li>
<li><a href="Binary_search_tree" title="Binary search tree">Binary search tree</a></li>
<li><a href="Fenwick_tree" title="Fenwick tree">Fenwick tree</a></li>
<li><a href="Graph_(abstract_data_type)" title="Graph (abstract data type)">Graph</a></li>
<li><a href="Hash_table" title="Hash table">Hash table</a></li>
<li><a href="Heap_(data_structure)" title="Heap (data structure)">Heap</a></li>
<li><a href="Linked_list" title="Linked list">Linked list</a></li>
<li><a href="Queue_(abstract_data_type)" title="Queue (abstract data type)">Queue</a></li>
<li><a href="Segment_tree" title="Segment tree">Segment tree</a></li>
<li><a href="Stack_(abstract_data_type)" title="Stack (abstract data type)">Stack</a></li>
<li><a href="String_(computer_science)" title="String (computer science)">String</a></li>
<li><a href="Tree_(abstract_data_type)" title="Tree (abstract data type)">Tree</a></li>
<li><a href="Trie" title="Trie">Trie</a></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">Algorithms and <a href="Algorithmic_paradigm" title="Algorithmic paradigm">algorithmic paradigms</a></th><td class="navbox-list-with-group navbox-list navbox-even" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Backtracking" title="Backtracking">Backtracking</a></li>
<li><a href="Binary_search" title="Binary search">Binary search</a></li>
<li><a href="Breadth-first_search" title="Breadth-first search">Breadth-first search</a></li>
<li><a href="Brute-force_search" title="Brute-force search">Brute-force search</a></li>
<li><a href="Depth-first_search" title="Depth-first search">Depth-first search</a></li>
<li><a href="Divide-and-conquer_algorithm" title="Divide-and-conquer algorithm">Divide and conquer</a></li>

<li><a href="Graph_traversal" title="Graph traversal">Graph traversal</a></li>
<li><a href="Fold_(higher-order_function)" title="Fold (higher-order function)">Fold</a></li>
<li><a href="Greedy_algorithm" title="Greedy algorithm">Greedy</a></li>
<li><a href="Hash_function" title="Hash function">Hash function</a></li>
<li><a href="Minimax" title="Minimax">Minimax</a></li>
<li><a href="Online_algorithm" title="Online algorithm">Online</a></li>
<li><a href="Randomized_algorithm" title="Randomized algorithm">Randomized</a></li>
<li><a href="Recursion_(computer_science)" title="Recursion (computer science)">Recursion</a></li>
<li><a href="Root-finding_algorithm" title="Root-finding algorithm">Root-finding</a></li>
<li><a href="Sorting_algorithm" title="Sorting algorithm">Sorting</a></li>
<li><a href="Streaming_algorithm" title="Streaming algorithm">Streaming</a></li>
<li><a href="Sweep_line_algorithm" title="Sweep line algorithm">Sweep line</a></li>
<li><a href="String-searching_algorithm" title="String-searching algorithm">String-searching</a></li>
<li><a href="Topological_sorting" title="Topological sorting">Topological sorting</a></li></ul>
</div></td></tr><tr><td class="navbox-abovebelow" colspan="2"><div>
<ul><li><a href="List_of_data_structures" title="List of data structures">List of data structures</a></li>
<li><a href="List_of_algorithms" title="List of algorithms">List of algorithms</a></li></ul>
</div></td></tr></tbody></table></div>
<div class="navbox-styles"></div><div role="navigation" class="navbox authority-control" aria-labelledby="Authority_control_databases_frameless&amp;#124;text-top&amp;#124;10px&amp;#124;alt=Edit_this_at_Wikidata&amp;#124;link=https&amp;#58;//www.wikidata.org/wiki/Q380679#identifiers&amp;#124;class=noprint&amp;#124;Edit_this_at_Wikidata1058" style="padding:3px"><table class="nowraplinks hlist mw-collapsible autocollapse navbox-inner" style="border-spacing:0;background:transparent;color:inherit"><tbody><tr><th scope="col" class="navbox-title" colspan="2"><div id="Authority_control_databases_frameless&amp;#124;text-top&amp;#124;10px&amp;#124;alt=Edit_this_at_Wikidata&amp;#124;link=https&amp;#58;//www.wikidata.org/wiki/Q380679#identifiers&amp;#124;class=noprint&amp;#124;Edit_this_at_Wikidata1058" style="font-size:114%;margin:0 4em">Authority control databases </div></th></tr><tr><th scope="row" class="navbox-group" style="width:1%">National</th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em"><ul><li><span class="uid"><a rel="nofollow" class="external text" href="https://d-nb.info/gnd/4125677-3">Germany</a></span></li><li><span class="uid"><a rel="nofollow" class="external text" href="https://id.loc.gov/authorities/sh85040313">United States</a></span></li><li><span class="uid"><a rel="nofollow" class="external text" href="https://catalogue.bnf.fr/ark:/12148/cb11978098s">France</a></span></li><li><span class="uid"><a rel="nofollow" class="external text" href="https://data.bnf.fr/ark:/12148/cb11978098s">BnF data</a></span></li><li><span class="uid"><a rel="nofollow" class="external text" href="https://id.ndl.go.jp/auth/ndlna/00571739">Japan</a></span></li><li><span class="uid"><a rel="nofollow" class="external text" href="https://datos.bne.es/resource/XX543843">Spain</a></span></li><li><span class="uid"><a rel="nofollow" class="external text" href="https://www.nli.org.il/en/authorities/987007567971605171">Israel</a></span></li></ul></div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">Other</th><td class="navbox-list-with-group navbox-list navbox-even" style="width:100%;padding:0"><div style="padding:0 0.25em"><ul><li><span class="uid"><a rel="nofollow" class="external text" href="https://lux.collections.yale.edu/view/concept/cc665e92-424f-433f-a61c-60e09af71124">Yale LUX</a></span></li></ul></div></td></tr></tbody></table></div></div><!--htdig_noindex--><div><div class="zim-footer">
This article is issued from <a class="external text" title="Last edited on 2025-07-28" href="https://en.wikipedia.org/wiki/?title=Dynamic_programming&amp;oldid=1302979653">Wikipedia</a>. The text is available under <a class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">Creative Commons Attribution-Share Alike 4.0</a> unless otherwise noted. Additional terms may apply for the media files.
</div>
</div><!--/htdig_noindex--></div>
</div>
</main>
</div>
</div>
</div>

</body></html>